我在 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/