【发布时间】:2010-11-12 10:19:44
【问题描述】:
我(仅)安装了 Visual Studio 2010。我正在尝试从命令行构建系统运行我的单元测试。我所有的开发工作都在我使用 Samba 共享的 Linux 服务器上的主目录中。当我尝试运行 NUnit 时,出现如下错误:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'NUnit.ConsoleRunner.Runner' threw an exception. ---> System.Security.Security
Exception: That assembly does not allow partially trusted callers.
at NUnit.ConsoleRunner.Runner..cctor()
The action that failed was:
LinkDemand
The assembly or AppDomain that failed was:
nunit-console-runner, Version=2.5.9.10305, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77
The method that caused the failure was:
NUnit.Core.Logger GetLogger(System.Type)
The Zone of the assembly that failed was:
Intranet
The Url of the assembly that failed was:
file:///Z:/gitrepos/smarties/dependencies/Windows-x86/NUnit-2.5.9.10305/bin/net-2.0/lib/nunit-console-runner.DLL
--- End of inner exception stack trace ---
at NUnit.ConsoleRunner.Runner.Main(String[] args)
at NUnit.ConsoleRunner.Class1.Main(String[] args)
我已尝试使用 caspol.exe,如下所述:Edit and run .NET projects from network shares
>caspol -addgroup 1.2 -url file:///Z:/* FullTrust -name MyZShare
Microsoft (R) .NET Framework CasPol 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
WARNING: The .NET Framework does not apply CAS policy by default. Any settings shown or modified by CasPol will only affect applications that opt into using
CAS policy.
Please see http://go.microsoft.com/fwlink/?LinkId=131738 for more information.
The operation you are performing will alter security policy.
Are you sure you want to perform this operation? (yes/no)
yes
Added union code group with "-url" membership condition to the Machine level.
Success
效果不明显。
其他说明告诉我在控制面板的管理工具中找到一些 Microsoft .NET 安全策略工具,但我没有这样的工具可用。 (这是因为我只有 Visual Studio 2010,而不是更早的版本吗?我正在运行 Windows 7 Pro 64 位,如果有区别的话。)
我真的只是想让 .NET 相信这个目录在我自己的机器上,而不是 Intranet 的一部分。我不希望任何代码在部署时从网络共享运行,仅作为开发的一部分。我也不想盲目地信任所有网络共享,尽管即使这样也比每次我想运行测试时都将所有内容复制到本地驱动器上更容易接受。
在开发的这个阶段,我宁愿不必用强名称签署所有内容。 (而且我什至不确定它是否会有所帮助,因为 NUnit 显然在加载我的程序集之前就失败了。)
编辑 - 最后结果证明我试图解决错误的问题。在弄清楚如何让 NUnit 在没有子进程的情况下运行 .NET 4.0 测试时,我发现了这一点:
http://frater.wordpress.com/2010/05/04/debugging-nunit-tests-under-visual-studio-2010/
上面写着:
根据this page,您还应该在运行时元素下添加这一行 [in nunit-console.exe.config]:
<loadFromRemoteSources enabled="true" />这允许从远程站点(例如网站)下载的库以完全信任的方式加载。我不确定为什么这是必要的,事实上,我的应用程序在没有它的情况下调试 NUnit 就好了。但是,如果您有问题,您可能想尝试一下。
这为我解决了我的问题,而无需与 caspol 搞混。
【问题讨论】:
-
我认为您真正想要做的是在 Internet 设置->安全中启用“本地 Intranet”区域,并将 UNC 路径添加到该区域。您也可以尝试调整信任设置。我对此不是 100% 确定,因此我将其作为评论而不是答案。
标签: .net security visual-studio-2010 nunit