views:

3879

answers:

4

I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under Program Files, and I keep getting this error when trying to load my tests.

Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified

In order to simplify the problem, I've compiled the most basic possible test file.

using NUnit.Framework;

namespace test
{
    [TestFixture]
    public class Tester
    {
     [Test]
     public void ATest()
     {
      Assert.IsTrue( false, "At least the test ran!" );
     }
    }
}

I've added "C:\Program Files\NUnit-2.4.8-net-2.0\bin" to my PATH (and rebooted). Note that if I copy the test assembly into that folder, then

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll

works, but

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll

and

C:\dev\nunit_test>nunit_console test.dll

fail with the above error.

Presumably I could get around this by copying the NUnit.Framework dll into my project's bin folder, but I don't remember having to do this in the past. Moreover, I get the same error in the GUI. Shouldn't the GUI know where the framework is located (that is, in the same folder)?

@Scott, I'm not using Visual Studio. I use the following line to compile the test project.

%windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs

@devio, I tried both the msi and the zip with the same result.

+5  A: 

Make sure you have added a reference to nunit.framework. If you have, then make sure the properties of that reference have the copy local property set to true.

Scott Pedersen
+4  A: 

If you install using NUnit-2.4.8-net-2.0.msi, the NUnit assemblies are added to the GAC.

You can also reinstall manually by runnig gacutil from the VS2005 Command Prompt.

devio
For whatever reason, I had this problem even after installation, but I added the assemblies to the GAC myself, and this has done the trick.
harpo
Thanks! 2.4.8 is working.
axk
Just an update, this is the still the case for NUnit 2.5.7 on Windows 7. I can build tests just by dropping nunit.framework in \windows\assembly.
harpo
+4  A: 

I had the same problem and I had installed using NUnit-2.4.8-net-2.0.msi. Expanding on the "add to the gac" comment above, here's what I did:

  • Open your "visual sudio command prompt (generally: make sure gacutil is in your path) and: cd "C:\Program Files\NUnit 2.4.8\bin"

  • Unregister your nunit entries from the gac. You can do this by finding the nunit entries registered in the gac:

gacutil /l | find /i "nunit" > temp.bat && notepad temp.bat

  • Prepend the nunit.core and nunit.framework lines with "gacutil /uf", i.e.:

gacutil /uf nunit.core,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77

gacutil /uf nunit.framework,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77

  • Run your bat file to remove them: temp.bat

  • Register the nunit dlls you need: gacutil /i nunit.core.dll

gacutil /i nunit.framework.dll

Jeffrey Knight
A: 

I got this error message today when I tried to add a new test assembly to an existing NUnit test project. It seems that my test projects had multiple path references to identical nunit.framework.dll assemblies.

If you have more than one test assembly in your NUnit project, you may want to verify the Path property of the nunit.framework reference in your test projects. Once I made them match, the error message went away.

Curt