NUnit + BadImageFormatException

I got NUnit to run by telling VS to copy the NUnit.Framework dll locally.  However, when i tried starting nunit i got the following exception:

Exception Details
System.BadImageFormatException: The format of the file ‘Testing.Collections.Tests’ is invalid.

File name: “Testing.Collections.Tests”

Server stack trace:
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)

   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)

   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark)

   at System.AppDomain.Load(String assemblyString)

   at NUnit.Core.TestSuiteBuilder.Load(String assemblyName)

   at NUnit.Core.TestSuiteBuilder.Build(String assemblyName, Int32 assemblyKey)

   at NUnit.Core.RemoteTestRunner.BuildSuite()

   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)

   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)

   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)

   at NUnit.Core.TestDomain.LoadAssembly(String assemblyFileName, String testFixture)

   at NUnit.Util.NUnitProject.LoadTest(TestDomain testDomain, String testFixture)

   at NUnit.Util.TestLoader.LoadTest()


=== Pre-bind state information ===

LOG: DisplayName = Testing.Collections.Tests

LOG: Appbase = C:\Development\cyrusn\Testing\Testing.Collections.Tests\bin\Debug

LOG: Initial PrivatePath = C:\Development\cyrusn\Testing\Testing.Collections.Tests\bin\Debug

Calling assembly : nunit.framework, Version=, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77.


LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Post-policy reference: Testing.Collections.Tests

LOG: Attempting download of new URL file:///C:/Development/cyrusn/Testing/Testing.Collections.Tests/bin/Debug/Testing.Collections.Tests.DLL.


My guess is that NUnit doesn’t support assemblies that use the new runtime features like generics.  I’m going to see if I can work around this at all.

Comments (11)

  1. Dave Montgomery says:

    Are you using Whidbey? I had the same until I added the following in my NUnit-gui.exe.config and NUnit-Console.exe.config files:

    <supportedRuntime version="v2.0.40301" />

  2. Lancer says:

    Doesn’t work for me. I still get the exception. I’m not running the GUI integrated with VS, I’m just clicking on the gui icon.

  3. Lancer says:

    What’s happening is that this exception is thrown as soon as I load a .dll built with Whidbey. Nunit gui itself runs fine.

  4. gisoo says:

    hi please help me.give me consol code for nunit please

  5. Calfon_Zhai says:

    I resolved the mystery.

    It seemed that the "nunit-gui.exe.config" file caused the issue. The orginal value about encoding xml attribute is "Windows-1252". Setting encoding attribute with new value "UTF8"(not "utf-8") you can run nunit-gui.exe successfuly without vs2005 IDE. However, it keep the same error if you launch nunit within vs2005 IDE.

    the incorrect sinnpet about nunit.exe.config:

    <?xml version="1.0" encoding="Windows-1252"?>

    the correct sinnpet about nunit.exe.config:

    <?xml version="1.0" encoding="UTF8"?>

  6. Dan Vallejo says:

    Nope. That’s not it. It wasn’t the Windows-1252. It’s the ordering of the supported runtime tag. I left the Windows-1252 alone and just moved up the supported tag for 2.0 to be first and that fixed it.

  7. lkhui says:

    The method above is work.

    The problem is you didnt remove the tag commented on configuration/startup in the nunit-console.exe.config.



    <supportedRuntime version="v2.0.50727" />

    <supportedRuntime version="v2.0.50215" />

    <supportedRuntime version="v2.0.40607" />

    <supportedRuntime version="v1.1.4322" />

    <supportedRuntime version="v1.0.3705" />

    <requiredRuntime version="v2.0.50727" />



    You should notice and remove this tag commented (<!–……..–>) and so the nunit-console.exe didnt and cannot read the setting in <startup>

  8. akucheck says:

    I am running the release version of VS 2005, with NUnit 2.2.3. I still get the same exception, even after moving up the v2.0 runtime line in the startup section [tried both "supported" and "required"]. I also tried the UTF8 change. No luck so far. Any other ideas?

  9. akucheck says:

    Follow-up to my comment above: I just installed TestDriven.Net 2.0. The NUnit installed with TD [still 2.2.3]. runs within VS 2005 now, albeit with some idiosyncracies. The same version of NUnit launched outside of VS 2005 no longer exhibits the "BadImageFormat" behavior, but also finds zero tests in my testfixture. ;>(

  10. akucheck says:

    [hopefully] Last post on this topic: Got the TD version of NUnit 2.2.3 to work fine outside of VS 2005. Cannot determine the difference between that install and the straight DL and install from the site, but one works, the other doesn’t. Hmmm…


  11. Great blog says:

    Your blog is really very interesting.