hello temp10
hello temp10

Reputation: 41

System.BadImageFormatException while using NUnit and Resharper

I am using Visual Studio 2010 and Resharper 9.0. I have 64 bit system. I have NUnit 2.6.4

I get this when I try to run any test. No tests work here. Can anyone please tell how to solve this error.

Error:

System.BadImageFormatException : Could not load file or assembly 'NUnitFirst, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Upvotes: 2

Views: 1066

Answers (2)

Sri Harsha
Sri Harsha

Reputation: 21

If you compiled to x64 bit use nunit.exe else use nunit-x86.exe

Upvotes: 0

citizenmatt
citizenmatt

Reputation: 18603

This is most likely due to your test assembly being compiled to 64 bit when your production code requires 32 bit, or vice versa. ReSharper's test runner will launch a hosting process, based on your test assembly (.net 4.0 or 4.5, 32 or 64 bit, etc.). If the project is marked as 32 bit, 64 bit, or AnyCPU, it launches the appropriate hosting application.

If your production assembly requires e.g. 64 bit, but your test assembly is 32 bit, the 32 bit test hosting application is launched, and that is unable to load the production assembly, and throws the BadImageFormatException.

The solution is to change the bit-ness of the test assembly to match the production assembly.

Upvotes: 3

Related Questions