【问题标题】:I am getting System.BadImageFormatException : The operating system cannot run exception while running unit tests我收到 System.BadImageFormatException :运行单元测试时操作系统无法运行异常
【发布时间】:2012-06-07 05:38:28
【问题描述】:

我正在开发一个 Winforms 项目。目前我面临一个问题,运行一些测试用例会抛出

    System.BadImageFormatException : The operating system cannot run . 
(Exception from HRESULT: 0x800700B6)

异常。仅当我通过 NUnit 运行测试时才会发生这种情况。但是,如果我通过代码运行应用程序,它就可以正常工作。

应用程序中正在使用远程处理。这会是个问题吗?

【问题讨论】:

    标签: c# .net nunit badimageformatexception


    【解决方案1】:

    确保 NUNIT 和您的代码都编译到相同的平台 - x86 或 x64。将平台设置为“任何 CPU”的最简单方法 在你的代码上。

    【讨论】:

    • 它是一个叫做 'AnyCPU' 而不是 'both' ;p
    • 如何查看 NUnit 编译到哪个平台?
    • 只需将您的设置更改为“任何 cpu”(感谢@leppie),无论 NUnit 是如何编译的,它都应该可以工作。
    • 已经是“AnyCPU”了。这是我的第一个预感。但它没有工作
    • 我正在使用 x86 机器。那么,改成 x64 有意义吗?
    【解决方案2】:

    我有类似的问题,但在我的情况下,应用程序的配置文件有所帮助。该文件包含以下条目:

    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <requiredRuntime version="v4.0" />
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
        </startup>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2014-02-26
      • 2013-02-09
      • 2022-09-11
      • 2013-09-22
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多