Moq BadImageFormatException with NUnit

Created 16 November 2010 12:05
I ran into an issue today running a unit test where I kept getting a System.BadImageFormatException on the test dll. I incorrectly assumed this was NUnit - after digging around a bit I worked out it was actuall Moq that was the source of the problem.

The return value of the object being verified existed in an assembly that was not being referenced by my test project, and Moq was falling over. Adding the reference sorted out the problem.

The exact error I encountered was:

Test.MyLongNamespace.MyTestmethod: System.BadImageFormatException : [C:\Users\matt salmon\AppData\Local\Temp\ ....MyAssembly.DLL] The signature is incorrect.
Nick on 16 March 2011 at 13:19
Thanks! Just found this by Google and it saved me some time.
Matt on 22 July 2011 at 16:09
Thank you very very much. I have just had this happen to me and this post helped me sort it out nice and quickly.
Roel Stolker on 18 January 2012 at 18:22
Nice catch! I could not make much sense out this error.
Anonymous on 03 March 2012 at 10:08
Thank you!! This was very annoying.
Anonymous on 02 June 2012 at 20:51
Thanks! This was exactly my problem
Marcin on 30 September 2014 at 09:09
Thanks! This was very helpful!