c# - 在 Release模式下构建时发生 System.BadImageFormatException

标签 c# .net assembly-resolution

我在 dll 中引用一个 exe 文件。在DEBUG 模式 下运行时一切正常,但在Release 模式 下运行时会抛出异常

System.BadImageFormatException occurred
  HResult=-2147024885
  Message=Could not load file or assembly 'Presensoft.InlineMarker, 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.
  Source=Presensoft.ApplicationServer
  FileName=Presensoft.InlineMarker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog==== Pre-bind state information ===
LOG: DisplayName = Presensoft.InlineMarker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///F:/PresensoftNewTrunk/Trunk/Email Archiver/EmailService/Presensoft.ApplicationServerHost/bin/Release/
LOG: Initial PrivatePath = NULL
Calling assembly : Presensoft.ApplicationServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: F:\PresensoftNewTrunk\Trunk\Email Archiver\EmailService\Presensoft.ApplicationServerHost\bin\Release\Presensoft.ApplicationServerHost.vshost.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\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:///F:/PresensoftNewTrunk/Trunk/Email Archiver/EmailService/Presensoft.ApplicationServerHost/bin/Release/Presensoft.InlineMarker.DLL.
LOG: Attempting download of new URL file:///F:/PresensoftNewTrunk/Trunk/Email Archiver/EmailService/Presensoft.ApplicationServerHost/bin/Release/Presensoft.InlineMarker/Presensoft.InlineMarker.DLL.
LOG: Attempting download of new URL file:///F:/PresensoftNewTrunk/Trunk/Email Archiver/EmailService/Presensoft.ApplicationServerHost/bin/Release/Presensoft.InlineMarker.EXE.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

  StackTrace:
       at Presensoft.ApplicationServer.ExchangeServer2010Push.PostProcessingEmailsQueue()
       at Presensoft.ApplicationServer.ExchangeServer2010Push.RunPushService(Guid appServerID) in f:\PresensoftNewTrunk\Trunk\Email Archiver\EmailService\Presensoft.ApplicationServer\ExchangeServer2010Push.cs:line 48
  InnerException: 

不确定在RELEASE 模式 下运行时probing exe 文件是否有问题。

最佳答案

不仅仅是调试/ Release模式,我会说这是一个 32 位与 64 位的问题。可能您将 Debug模式的平台目标设置为自动,将 Release模式设置为 32/64 位,并且您使用的 dll 仅为 32 或 64 位,因此在调试(平台目标自动) 模式下,.NET 可以在 32 位和 64 位之间“选择”以与 dll 兼容,而在发布(平台目标 32 位或 64 位)中则不能。

(请注意,如果您在同一解决方案中有多个项目,则必须为此检查所有项目属性!它在每个项目、构建、平台目标的属性中)

关于c# - 在 Release模式下构建时发生 System.BadImageFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719339/

相关文章:

.net - 使用 javascript 解密数据 - ASP.NET 网站

c# - 使用正则表达式捕获分隔符内的子字符串并排除字符

c# - 如何从自定义目录动态加载程序集,包括其依赖项?

c# - 调试时停止创建本地程序集

assemblies - 为什么尝试在NUnit 2.5.4下使用两个.NET 4.0程序集进行单元测试失败?

c# - 用 AutoFac 替换工厂

c# - Azure downloadtostreamasync 方法挂起

c# - 如何拥有 "public public"v/s "internal public"?

c# - WinForms:从其变量名中获取某个按钮

.net - 使用 .NET Core 发布带有自定义元数据的 NuGet 包