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
(Partial)
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=2.1.4.0, 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 .
---------------------------
OK
---------------------------
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
- Anonymous
May 18, 2004
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" /> - Anonymous
May 19, 2004
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.
lancerkind@yahoo.com - Anonymous
May 19, 2004
What's happening is that this exception is thrown as soon as I load a .dll built with Whidbey. Nunit gui itself runs fine.
lancerkind@yahoo.com - Anonymous
July 24, 2004
hi please help me.give me consol code for nunit please - Anonymous
June 05, 2005
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"?> - Anonymous
October 28, 2005
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. - Anonymous
November 15, 2005
The method above is work.
The problem is you didnt remove the tag commented on configuration/startup in the nunit-console.exe.config.
<!--
<startup>
<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" />
</startup>
-->
You should notice and remove this tag commented (<!--........-->) and so the nunit-console.exe didnt and cannot read the setting in <startup> - Anonymous
November 20, 2005
The comment has been removed - Anonymous
November 20, 2005
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. ;>( - Anonymous
November 20, 2005
[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 NUnit.org site, but one works, the other doesn't. Hmmm...
thanks - Anonymous
February 20, 2006
Your blog is really very interesting.