Dav*_*vid 24 c# 64-bit mstest visual-studio-2010
我似乎遇到了一个场景,当我在引用x64程序集的AnyCPU程序集上运行mstest时,我得到一个BadImageFormatException.
当AnyCPUTestingx64Production.dll测试程序集实现x64Production.dll中的接口(即使未使用)时,会出现此问题:
Unable to load the test container 'D:\AnyCPUTestingx64Production.dll'
or one of its dependencies. error details:
System.BadImageFormatException:
Could not load file or assembly 'x64Production, 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.
Run Code Online (Sandbox Code Playgroud)
*** Assembly Binder Log Entry (09/02/2012 @ 09:44:26) ***
The operation failed.
Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = David
LOG: DisplayName = x64Production, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///D:/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MSTest.exe
Calling assembly : AnyCPUTestingx64Production, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/x64Production.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\x64Production.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: x64Production, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Run Code Online (Sandbox Code Playgroud)
有没有其他人确定这是否在VS2010 mstest中根本不受支持?
Anu*_*pam 32
我来到这里寻找类似问题的解决方案.发布这个答案,以防我找到的解决方案帮助其他人.这在Visual Studio(2012)中为我解决了这个问题:
添加新项目 - >测试设置
更改测试设置
默认情况下,此项设置为"强制测试以32位进程运行"
从菜单中:测试 - >测试设置 - >选择测试设置文件 - >选择您创建的测试设置文件.
现在运行测试.
Jus*_*ing 18
现在使用Visual Studio 2013(至少在2012年没有尝试)我不需要做任何事情,只需选择Test-> Test Settings-> Default Processor Architecture-> x64.也可以使用测试设置文件来实现相同的结果.你在其他答案和网上发布的各种帖子中都看不到那些旧的克服.由于我的东西必须使用x64,我添加这些测试用例只是为了提醒我是否有一些设置错误.
[TestMethod]
public void Running_64Bit_OS()
{
// It was determined to run only in 64 bits.
bool is64BitOS = System.Environment.Is64BitOperatingSystem;
Assert.AreEqual(is64BitOS, true);
}
[TestMethod]
public void Running_64Bit_Process()
{
// We have a requirement that one of the unmanaged DLL is built for 64 bits.
// If you are running MS Test in Visual Studio 2013 and this
// is failing, go to Test->Test Settings->Default Processor Architecture and
// chose x64, then run the tests again. This is not the only method. You
// could also use a test settings file.
bool is64BitProcess = System.Environment.Is64BitProcess;
Assert.AreEqual(is64BitProcess, true);
}
Run Code Online (Sandbox Code Playgroud)
Jos*_*hua 13
从阅读本文来看,MSTest.exe是32位.