【发布时间】:2020-10-29 00:59:20
【问题描述】:
我似乎遇到了这样一种情况,当我在引用 x64 程序集的 AnyCPU 程序集上运行 mstest 时,我得到了 BadImageFormatException。
当 x64Production.dll 中的接口由 AnyCPUTestingx64Production.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.
- mstest 正在 Windows 7 64 位上运行
- 测试程序集构建为 AnyCPU,以使其在 64 位主机上以 64 位运行(如here 所述)
- testsettings 文件指定
- peverify 和 corflags 没有发现任何有趣的东西
- 这很容易在玩具解决方案中重现,即
- x64生产
- 不引用其他程序集
- 仅包含一个空的公共接口 IExampleInterface
- 已将
设置为 x64
- AnyCPUTestingx64Production
- 仅引用 x64Production.dll(即即使不引用 Microsoft.VisualStudio.QualityTools.UnitTestFramework 也会出现此问题)
- 仅包含 x64Production.IExampleInterface 的空实现
- 已将
设置为 x64
- x64生产
- nunit 可以加载和运行测试程序集(一旦我转换了所有测试属性)
- 但对于较大的问题(涉及大量项目文件)不是一个好的短期解决方案
- 无论项目的目标是 3.5 还是 4.0,都会出现同样的问题
- 无论使用 VS2008 还是 VS2010 c# 编译器都会出现相同的问题
- 无论是使用来自 VS2010 的 mstest 还是使用测试代理,都会出现同样的问题
- mstest 在加载 AnyCPUTestingx64Production 时失败 - 即尝试在错误的 QTAgent 中加载程序集不是问题(进程监视器中没有显示任何内容,重命名 QTAgent32.exe 无效):
*** 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.
有没有其他人确定这在 VS2010 mstest 中是否完全不受支持?
【问题讨论】:
-
构建一个针对 x64 的 DLL 毫无意义,始终以 AnyCPU 为目标。该设置仅对 EXE 项目重要。 Mstest 在 32 位模式下运行。
-
请考虑更改您接受的答案。现在有多种方法可以将测试平台配置为在 64 位以上运行。
标签: c# visual-studio-2010 mstest 64-bit