.net - 系统.BadImageFormatException : Could not load file or assembly or one of its dependencies

标签 .net 64-bit

我有一个与 System.BadImageFormatException: Could not load file or assembly 类似的错误. 但是引发错误的条件不同。

Test Name: Test_DisableTestUserAccount
Test FullName:
Test Source:
Test Outcome: Failed
Test Duration: 0:00:00

Result Message:
Unable to get type #typename#. Error: System.IO.FileLoadException: Could not load file or assembly 'ComponentName.IntTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a433f9a8cee952' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'ComponentName.IntTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=433f9a8cee952' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
The Zone of the assembly that failed was:
MyComputer
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.VisualStudio.TestPlatform.MSTestFramework.TypeCache.LoadType(String typeName, String assemblyName)

条件:

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

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

最佳答案

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

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

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

截图: enter image description here

关于.net - 系统.BadImageFormatException : Could not load file or assembly or one of its dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20675044/

相关文章:

.net - 使用 ODBC 和 C++ Net 将空 BLOB 插入 SQLite DB

windows - KEY_WOW64_64KEY 对 32 位 Windows 有什么影响吗?

python - 如何进一步调试 (win7 64bit, py2.7) 上的 SendKeysCtypes?

.net - 哪些代码控制 WPF 应用程序的启动?

C# VSTO 加载项 - 将纯文本电子邮件转换为 HTML

c# - System.FormatException 解码 Gmail 邮件的原始字段

c# - 将动态参数传递给类似的函数

.NET 相当于 size_t

asp.net-ajax - 奇怪的 ASP.NET AJAX Bug/32 位到 64 位

ios - 将架构更新为 64 位(标准)后出现神秘的 Xcode 链接器错误