我在dll中引用了一个exe文件。在 DEBUG模式中运行时,一切运行正常但在发布模式下运行时会抛出异常
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 文件是否存在问题。
答案 0 :(得分:7)
不仅仅是调试/发布模式我会说它是32比64位问题。可能你将Debug模式的平台目标设置为Auto,将Release模式设置为32/64位,并且你使用的是一个只有32或64位的dll,所以在Debug(Platform target Auto)中)模式.NET可以在32位和64位之间“选择”以与dll兼容,而在Release(平台目标32或64位)中它不能。
(请注意,如果您在同一个解决方案中有多个项目,则必须检查所有项目属性!它位于每个项目的属性中,Build,Platform target)
答案 1 :(得分:0)
我昨天遇到了这个(或类似的东西)。 Debug和Release模式都设置为AnyCPU,但exe引用的是32位dll。在调试时,exe似乎默认为32位(我假设因为Visual Studio是32位)但是在发布模式下,它切换到64位(我假设因为我的计算机是64位)。因此,当我强制它始终是32位(x86)时,一切都应该并且确实很有效!希望这有帮助!