简体   繁体   English

NUnit无法使用字符串键名加载dll

[英]NUnit unable to load dll with String Key Name

I have a project in which I have some C# classes which I am building using csc in my ant script. 我有一个项目,其中有一些C#类,这些类是在ant脚本中使用csc构建的。 I have also have written some unit tests which I want to test with NUnit2.6 , My test class and actual class refer to one DLL which is compiled with String Key Name (.snk), if I install thi DLL in my GAC (gacutil /i myDLL.dll) everything works fine. 我还编写了一些要使用NUnit2.6进行测试的单元测试,如果我在GAC中安装了DLL,我的测试类和实际类都引用了一个用字符串键名(.snk)编译的DLL。 / i myDLL.dll),一切正常。 As soon as I uninstall this DLL from my gac I get following error for all the test during the build when I try to run my test using NUnit; 当我从gac卸载此DLL时,当我尝试使用NUnit运行测试时,在构建期间的所有测试都会出现以下错误;

Test Error : fromJDynTest1
 [exec]    System.IO.FileNotFoundException : Could not load file or assembly 'myDLL, Version=5.1.0.0, Culture=neutral, PublicKeyToken=c0409b584f86b2d6' or one of its dependencies. The system cannot find the file specified.
 [exec]    at fromJDynTest1()
...
...

Does anyone know how to resolve this. 有谁知道如何解决这个问题。 Let me know if you need any other information. 让我知道您是否需要其他信息。

Thanks 谢谢

-- -

SJunejo 俊城

The code you are testing cannot see the assembly in question when you place it in the gac it can see the assembly. 当您将要测试的代码放入GAC中时,看不到有问题的程序集,它可以看到程序集。 You need to ensure that the code you are testing has the assembly in the bin directory when compiled (perhaps copy local is set to false in your project on the assembly reference). 您需要确保编译时正在测试的代码在bin目录中具有该程序集(也许在程序集引用上的项目中将copy local设置为false)。

The reason I am sure it is not a dependency (which is mentioned in the message) is because the situation is resolved when the assembly is placed in the gac. 我确定它不是依赖项(在消息中提到)的原因是,当将程序集放置在gac中时,情况已解决。 This error is not likely caused because the assembly is strongly named. 因为程序集是强命名的,所以不太可能导致此错误。

Failing that the test code refers to the assembly and that test code either doesn't have a reference or has the same problem (not in its compiled directory). 无法通过测试代码引用程序集,并且该测试代码没有引用或存在相同的问题(不在其编译目录中)。

Would help if you posted the actual test or structure of the project. 如果您发布了项目的实际测试或结构会有所帮助。

.net locates assemblies as follows: .net按以下方式查找程序集:

  1. Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. 通过检查适用的配置文件(包括应用程序配置文件,发布者策略文件和计算机配置文件)来确定正确的程序集版本。 If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first. 如果配置文件位于远程计算机上,则运行时必须首先找到并下载应用程序配置文件。
  2. Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. 检查程序集名称之前是否已绑定,如果是,则使用先前加载的程序集。 If it failed before it will fail again now. 如果之前失败,则现在将再次失败。
  3. Checks the gac. 检查gac。 If the assembly is found there, the runtime uses this assembly. 如果在此找到程序集,则运行时将使用此程序集。
  4. Probes for the assembly (if you open up a .csproj file in a text editor you will see hintpaths, which try and help .net find the assembly). 程序集的探针(如果您在文本编辑器中打开.csproj文件,则将看到提示路径,它们会尝试帮助.net查找程序集)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM