This blog has moved, permanently, to http://software.safish.com.

Tuesday, November 16, 2010

Moq BadImageFormatException with NUnit

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\nunit20\ShadowCopyCache\9748_634255057586445703\Tests_64256578\assembly\dl3\5181e02b\57ddb865_7585cb01\MyAssembly.DLL] The signature is incorrect.

10 comments:

  1. Thanks! Just found this by Google and it saved me some time.

    ReplyDelete
  2. Thank you very very much. I have just had this happen to me and this post helped me sort it out nice and quickly.

    ReplyDelete
  3. Nice catch! I could not make much sense out this error.

    ReplyDelete
  4. Thank you!! This was very annoying.

    ReplyDelete
  5. Thanks! This was exactly my problem.

    ReplyDelete
  6. Also, you may require a reference to an assembly in your test project. In my case I needed to add System.Messaging for an MSMQ proxy class I'd written and was trying to mock.

    ReplyDelete
  7. Thanks for help on this one!

    ReplyDelete
  8. My problem, too. Very frustrating and unhelpful error message. Thanks for posting this.

    ReplyDelete

Note: Only a member of this blog may post a comment.