这个论坛上有很多有关的问题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添加HKEY_CURRENT_USER \ Software \ Microsoft \ VisualStudio \ 12.0 \ WebProjects / v Use64BitIISExpress / t REG_DWORD / d 1
(我认为您必须重新启动Visual Studio)
אתהגאון!תודהרבה,אחי
我必须等到明天,才能授予您赏金... :)
对于Visual Studio 2019,请参阅以下过程。