Could not load file or assembly nunit.core
I recently upgraded to the latest version of NUnit (2.2.8) [1] and when I ran some tests on a library I’m currently working on using TestDriven.Net I got the following error (error #1).
“Could not load file or assembly ‘nunit.core, Version=2.2.6.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77’ or one of its dependencies. The system could not find the specific file.”
System.IO.FileNotFoundException...
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
at NUnit.Util.TestDomain.MakeRemoteTestRunner(AppDomain runnerDomain)
at NUnit.Util.TestDomain.Load(String assemblyFileName, String testFixture)
at NUnit.Util.TestLoader.LoadTest(String testName)
My first initial thought was that the install had gone wrong as it mentioned version 2.2.6.0 – not 2.2.8.0. After I googled the problem I found a thread on TestDriven.Net User Google group [2], where what seemed to be the same problem was being discussed. The solution offered in this thread was to check the reference to nunit.framework was the correct version and recompile. Unfortunately this didn’t work and google was out of answers :(
Now I’m back to my initial thinking that it might be an install error so I open up the NUnit GUI directly and got the same error but this time the version number was 2.2.8.0 (error #2). This confused me even more as to what the problem was but convinced me that there was a problem with the install as I’d opened it up directly with out any tests, or had I. After uninstalling and reinstalling NUnit version 2.2.8.0 I opened up the NUnit GUI first and the error had gone, problem solved right? But when I ran the test directly with the GUI I get error #2 again!
After checking the options in the GUI, I realised that it loads the last library at start up (even if there's an error), which meant that my library was being loaded even when I opened the GUI directly, so out went the install problem idea – it had to be my library that I was testing. I decided to remove tests one by one but I first renamed the app.cofig file and ran nunit only to get an exception related to the config settings being missing. Before going on my little adventure I’d trailed through the config file (it was only a few lines in length) and was convinced that it was correct – but after closer inspection I discovered a single character was missing in a configSections section name. After correcting the spelling the tests ran (and passed) with out any problems.
I would have thought that nunit would have been able to handle congfig errors related to the loaded library being tested and display a more meaningfully error and that if a library fails to load that it wouldn’t be reloaded on startup again.
[1] http://www.nunit.org/
[2] http://groups.google.com/group/TestDrivenUsers/browse_thread/thread/82a6d4c7d5b50ddd/875747b90308af8f