System.BadImageFormatException:无法加载文件或程序集...尝试使用 installutil.exe 安装服务时格式不正确

问题描述:

我知道我要问重复 问题,但我认为我的情况完全不同,因为当我使用程序的 nunit 工具进行单元测试时,在 NUnit 中会发生此错误

I know i am going to ask duplicate question but my scenario is totally different i think so because when i go to do unit testing with nunit tool of my program then in NUnit this error happen

"NewTest.testtest(TestFixtureSetUp):设置:System.BadImageFormatException:无法加载文件或程序集AUTO_REPAIR,版本=1.0.0.0,Culture=neutral,PublicKeyToken=null"或其依赖项之一.试图加载格式不正确的程序."

"NewTest.testtest (TestFixtureSetUp): SetUp : System.BadImageFormatException : Could not load file or assembly 'AUTO_REPAIR, 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."

我想知道为什么这个工具会发生这个错误?我确信我在项目或任何测试用例中都没有错误.

I wonder why this error is happening to this tool ? i am sure i dont have error in project or in any test case.

请帮帮我.

这是此错误的图像

有两种方法可以解决这个错误

There are two ways to solve this error

  1. 在 Visual Studio 中将您的项目的平台目标设置为 x86(右键单击您的解决方案,然后转到属性,然后您将找到构建选项,当您单击构建时,您将找到平台目标).将平台目标设置为 x86 后,尝试使用 nunit 进行单元测试.

  1. 只需在您的 nunit 文件夹的 bin 文件夹中找到 nunit-x86.exe 并运行此 exe 文件,您将不会再看到任何异常:)