BadImageFormatException调试在x64模式下运行的网站

关于BadImageFormatException ,这个论坛上有很多问题,但没有一个问题与我的问题相符。

我有一个包含几个项目的解决方案。 当我在Debug或Release + Any CPU中运行时,一切正常。 然而,当我切换到x64并运行我的ASP.NET MVC项目时,我得到了臭名昭着的BadImageFormatException

无法加载文件或程序集“AgileEFLib”或其依赖项之一。 尝试加载格式不正确的程序。

AgileEFLib是一个内部实用程序库,因此我有足够的灵活性。 但真正奇怪的是,当我运行一个也依赖于AgileEFLib的控制台应用程序时,它运行得很好。 它失败的唯一时间是我运行网站时。

我已经检查过Release | x64配置中的所有项目都设置为编译为x64。

我还能做些什么来解决这个问题?

编辑:另一个有用的信息是这个问题只发生在我使用Visual Studio的IIS Express进行调试时。 当我发布并部署到IIS时,它工作正常。

编辑:有关错误的更多详细信息:

 Server Error in '/' Application. -------------------------------------------------------------------------------- Could not load file or assembly 'AgileEFLib' or one of its dependencies. An attempt was made to load a program with an incorrect format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.BadImageFormatException: Could not load file or assembly 'AgileEFLib' or one of its dependencies. An attempt was made to load a program with an incorrect format. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Assembly Load Trace: The following information can be helpful to determine why the assembly 'AgileEFLib' could not be loaded. === Pre-bind state information === LOG: DisplayName = AgileEFLib (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: AgileEFLib | Domain ID: 3 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///C:/src/MyProject/ LOG: Initial PrivatePath = C:\src\MyProject\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\src\MyProject\web.config LOG: Using host configuration file: C:\Users\Shaul\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\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:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/15406131/a0c36da/AgileEFLib.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/15406131/a0c36da/AgileEFLib/AgileEFLib.DLL. LOG: Attempting download of new URL file:///C:/src/MyProject/bin/AgileEFLib.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated. 

尝试按照使用64位IIS Express调试VS2013网站的说明进行操作:

如果您正在使用Visual Studio 2013(VS2013)中的ASP.NET MVC网站,则默认情况下,如果要将IIS Express作为64位进程运行,则需要进行一次注册表更改。 使用以下方法之一。

命令行:

reg add HKEY_CURRENT_USER \ Software \ Microsoft \ VisualStudio \ 12.0 \ WebProjects / v Use64BitIISExpress / t REG_DWORD / d 1

您可以使用Fuselogvw.exe 。 此实用程序将所有Fusion活动转储到日志中。 然后,您可以浏览日志并检查哪个DLL的格式错误。 您还必须了解AgileEFLib实际依赖的内容。 也许DLL本身不是问题,而是其依赖性之一。

我猜你的网站中的一个依赖DLL被编译为x86。

编辑:另请参阅Dependency Walker 。 这个显示了所有依赖项及其体系结构。

使用“AnyCPU”设置重建引用的程序集。 这将允许包含在其中的类在32位进程或64位进程中实例化。