March 28, 2007

NAnt-NUnit error

Ever have a weird error and there is nothing on Google to help you? This was one of those problems.

We are using nant to run all of our builds, and using the NUnit2 for testing. Just to help out, nant has a task called nunit2.

Unfortunately, every time I ran our build I would recieve this error:
[loadtasks] Failure scanning "C:\Program Files\nant-0.85\nant-0.85\bin\NAnt.NUnit2Tasks.dll" for extensions. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
That could have been a bit more helpful.

Fortunatly Reflector was able to save the day. I was able to find the NAnt.NUnit2Tasks.dll on my file system (not to hard, the error message told me right where to find it), and loaded it into Reflector.

From there I checked the references of the dll. Two caught my eye. nunit.core and nunit.util. Still using resharper I tried to expand the references...Resharper could not find them. And they did not exist in the same directory as NAnt.NUnit2Tasks.dll. That meant that nant was looking for them in the GAC and they were not there!

A quick little script proved that to be true. It looked like this:
gacutil.exe /l nunit.util

I received this message:
The Global Assembly Cache contains the following assemblies:

Number of items = 0

OK, enough debugging, I ran the following two scripts to put those two dlls in the GAC and everything worked fine:

C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin>gacutil.exe /i "C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit.core.dll"

C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin>gacutil.exe /i "C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit.util.dll"

No thanks Google, I'll just fix it myself thank you very much.

3 comments:

Anonymous said...

Try adding a nant\bin\lib\net\2.0 folder and adding the following files to it:

NDoc.Core.dll
NDoc.Documenter.Msdn.dll
NDoc.ExtendedUI.dll
nunit.core.dll
nunit.framework.dll
nunit.util.dll

This should make GAC'ing unnecessary which I highly recommend whenever possible. If you upgrade to the 3.5 framework you add a 3.5 folder with the same dll's.

Anonymous said...

Sorry, in your case, the folder would be:

C:\Program Files\nant-0.85\nant-0.85\bin\lib\net\2.0

Anonymous said...

You & Reflector saved my day :)

Thanks