【问题标题】:System.BadImageFormatException occurred when build in Release Mode在发布模式下构建时发生 System.BadImageFormatException
【发布时间】:2015-02-25 12:42:43
【问题描述】:

我在 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模式运行时探测exe文件是否存在问题。

【问题讨论】:

    标签: c# .net assembly-resolution


    【解决方案1】:

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

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

    【讨论】:

    • 这可能是相反的。假设 OP 有一个 64 位进程,而 exe 只有 32 位,当 DEBUG 设置为 32 位,并且 RELEASE 设置为 auto 时,您会遇到此问题。
    • 我检查了每个项目的属性,它们都是一样的。但是当我打开配置管理器时,位数有所不同。谢谢!!!
    • 我只是想说明一下。我只是与这个错误斗争了几个小时。除了安装 VS 2017 之外,我没有做任何更改,之后一切正常。我正在使用 2015。几个小时后回来并出现此错误。我多次清理解决方案并重建。从 TFS 一遍又一遍地获取最新信息,最后出乎意料的是,它在第​​ 10 次获取最新信息后开始工作。最后一次签到是我的。我真的认为 VS 中存在错误。
    • 忘记配置管理器。对我来说,那里的一切都是相同的 - AnyCPU,无论是调试还是发布。但是在项目属性 - Build - Targetplatform 中,在 Release 中设置了“Prefer 32 bit”标志:-/
    • "prefer 32 bit" 也出于某种原因在发布模式中设置为我......太令人沮丧了。
    【解决方案2】:

    我昨天也遇到了这个(或类似的)。 Debug 和 Release 模式都设置为 AnyCPU,但 exe 引用的是 32 位 dll。在调试时,exe 似乎默认为 32 位(我假设是因为 Visual Studio 是 32 位),但在发布模式下,它会切换到 64 位(我假设是因为我的计算机是 64 位)。因此,当我强制它始终为 32 位 (x86) 时,一切都应该而且确实很好用!希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2012-03-12
      相关资源
      最近更新 更多