1

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

SJunejo
  • 1,316
  • 4
  • 23
  • 39

1 Answers1

1

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).
krystan honour
  • 6,523
  • 3
  • 36
  • 63
  • I have added assembly path in PATH environment variable before executing the tests....Do I need to add to some other path as well? – SJunejo Apr 24 '12 at 22:47
  • it won't make any difference if its in the path env variable. you must follow the probe path of .net which is decribed in exteme detail here http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx Your application/tests simply cannot see the assembly check the assembly is referenced and is in the respective bin/debug bin/release directories or int he main bin of the web app. – krystan honour Apr 24 '12 at 22:50
  • 1
    Thanks, I have copied the my external DLL in NUnit/bin directory and everything worked great. Thanks for your spot on answer. – SJunejo Apr 24 '12 at 22:53