简体   繁体   中英

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. 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. 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;

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. 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).

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. 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:

  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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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