我只安装了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:编辑并从网络共享运行 .NET 项目
>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相信这个目录在我的机器上而不是内部网络的一部分。我不希望任何代码在部署时从网络共享运行,只能作为开发的一部分运行。我也不想盲目地信任所有网络共享,尽管即使这样做也比每次运行测试时都将所有内容复制到本地驱动器上更容易解决。
在开发阶段,我宁愿不必签署所有东西的强名称。(而且我甚至不确定它是否有所帮助,因为NUnit显然在加载我的程序集之前就失败了。)
编辑 - 最后,事实证明我试图解决错误的问题。在弄清楚如何在没有子进程的情况下运行.NET 4.0测试的同时,我找到了这个:
http://frater.wordpress.com/2010/05/04/debugging-nunit-tests-under-visual-studio-2010/
它说:
根据此页面,您还应在nunit-console.exe.config的运行时元素下添加此行:
<loadFromRemoteSources enabled="true" />
这允许从远程站点(如网站)下载的库以完全信任的方式加载。我不确定为什么会需要这样做,实际上,我的应用程序在没有它的情况下成功调试了NUnit。但是,如果您有问题,您可能需要尝试一下。
这为我解决了问题,而无需使用caspol。