在发布模式下生成时发生System.BadImageFormatException [英] System.BadImageFormatException occurred when build in Release Mode

查看:230
本文介绍了在发布模式下生成时发生System.BadImageFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dll中引用了一个exe文件.在 DEBUG模式下运行时,一切运行良好,但在发布模式下运行时,抛出以下异常

I am referencing an exe file in a dll. When run in DEBUG mode everything runs fine but when run in Release mode below exception is thrown

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 文件是否存在问题.

Not sure whether there is some issue with probing exe file when running in RELEASE mode.

推荐答案

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

More than a Debug/Release mode I'll say it's a 32 vs 64 bits problem. Probably you have the Platform target for the Debug mode to Auto and for the Release mode to 32/64 bits and you are using a dll that is only 32 or 64 bits, so in Debug (Platform target Auto) mode the .NET can "select" between 32 and 64 bits to be compatible with the dll, while in Release (Platform target 32 or 64 bits) it can't.

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

(note that if you have multiple projects in the same solution you have to check all the projects properties for this! It's in the properties of each project, Build, Platform target)

这篇关于在发布模式下生成时发生System.BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆