System.BadImageFormatException:无法加载文件或程序集或其依赖项之一

Ami*_*bha 2 .net 64-bit

我有一个类似于System.BadImageFormatException的错误:无法加载文件或程序集.但是解决错误的条件是不同的.

测试名称:Test_DisableTestUserAccount
测试FullName:
测试源:
测试结果:失败
测试持续时间:0 :00:00

结果消息:
无法获取#typename#类型.错误:System.IO.FileLoadException:无法加载文件或程序集'ComponentName.IntTest,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = a433f9a8cee952'或其依赖项之一.强名称验证失败.(来自HRESULT的异常:0x8013141A)
文件名:'ComponentName.IntTest,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 433f9a8cee952'---> System.Security.SecurityException:强名称验证失败.(来自HRESULT的异常:0x8013141A)
失败的程序集区域是: System.Reflection.RuntimeAssembly._nLoad中的
MyComputer
(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,
布料suppressSecurityChecks)在System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef) ,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFi 乐,证据securityEvidence,字节[]散列值,AssemblyHashAlgorithm的HashAlgorithm,布尔forIntrospection,布尔suppressSecurityChecks,StackCrawlMark&stackMark)
在System.Reflection.Assembly.LoadFrom(字符串assemblyFile)
在Microsoft.VisualStudio.TestPlatform.MSTestFramework.TypeCache.LoadType(字符串的typeName,字符串assemblyName)

条件:

  1. 该解决方案具有C#控制台应用程序及其UnitTest项目
  2. InternalsVisibleTo从控制台应用程序启用到单元项目
  3. 所有项目都是名字签名
  4. sln平台有两个配置:x64和x86(其他被删除)

当我运行将访问控制台应用程序的内部元素的单元测试用例时,测试用例将失败并抛出异常.

Ami*_*bha 10

问题的根本原因是我使用x64平台构建sln并使用x86测试设置运行测试用例.

只需使用正确的测试设置平台来运行测试用例:

  • 构建平台应该与运行测试用例的平台相同.

截图: 在此输入图像描述