简体   繁体   English

使用 NUnit 和 Resharper 时出现 System.BadImageFormatException

[英]System.BadImageFormatException while using NUnit and Resharper

I am using Visual Studio 2010 and Resharper 9.0.我正在使用 Visual Studio 2010 和 Resharper 9.0。 I have 64 bit system.我有64位系统。 I have NUnit 2.6.4我有 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.

This is most likely due to your test assembly being compiled to 64 bit when your production code requires 32 bit, or vice versa.这很可能是因为当您的生产代码需要 32 位时,您的测试程序集被编译为 64 位,反之亦然。 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.). ReSharper 的测试运行器将根据您的测试程序集(.net 4.0 或 4.5、32 或 64 位等)启动托管进程。 If the project is marked as 32 bit, 64 bit, or AnyCPU, it launches the appropriate hosting application.如果项目被标记为 32 位、64 位或 AnyCPU,它会启动相应的托管应用程序。

If your production assembly requires eg 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 .如果您的生产程序集需要例如 64 位,但您的测试程序集是 32 位,则启动 32 位测试托管应用程序,并且无法加载生产程序集,并抛出BadImageFormatException

The solution is to change the bit-ness of the test assembly to match the production assembly.解决方案是更改测试组件的位数以匹配生产组件。

如果你编译为 x64 位使用nunit.exe否则使用nunit-x86.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM