简体   繁体   English

BadImageFormatException:无法加载文件或程序集...格式错误 - 仅适用于Web应用程序

[英]BadImageFormatException: Could not load file or assembly … bad format - Only with Web Application

I am working on a Web Application on a Windows 8 64 bit machine using multiple existing libraries. 我正在使用多个现有库在Windows 8 64位计算机上处​​理Web应用程序。 I want to use two C# DLLs referencing one native DLL. 我想使用引用一个本机DLL的两个C#DLL。 Both C# DLLs are compiled for 64bit usage and tested in test applications. 两个C#DLL都编译为64位使用,并在测试应用程序中进行测试。 My web application references both C# DLLs and is supposed to run on IIS 8. I added the two C# DLLs as references to the project and the native DLL manually to the bin folder of the web app. 我的Web应用程序引用了两个C#DLL,并且应该在IIS 8上运行。我将两个C#DLL作为对项目的引用和本机DLL手动添加到Web应用程序的bin文件夹中。 Whenever I build and run the solution I get the exception shown in the title. 每当我构建并运行解决方案时,我都会得到标题中显示的异常。 I know that this is a sign for a problem regarding 32 bit and 64 bit code running in one process. 我知道这是在一个进程中运行32位和64位代码的问题的标志。 Therefore I tried all different build configurations but the result never changed. 因此,我尝试了所有不同的构建配置,但结果从未改变。

I created a console application doing exactly what I'm trying in the web app and it worked flawlessly. 我创建了一个控制台应用程序正在完成我正在尝试的Web应用程序,它运行完美。 The Web application with the exact same settings however throws the exception, this is what is really confusing to me. 具有完全相同设置的Web应用程序会抛出异常,这对我来说真的很混乱。

What I tried so far: 到目前为止我尝试了什么:

  • Change application pool setting to "enable 32-bit applications" 将应用程序池设置更改为“启用32位应用程序”
  • Build all DLLs with Any CPU, 64Bit or x86 target 使用任何CPU,64位或x86目标构建所有DLL
  • Check the corflags of all DLLs 检查所有DLL的corflags

I can provide an export of the project to everybody willing to help me get this configuration running! 我可以向愿意帮助我运行此配置的每个人提供项目导出!

I really appreciate every bit of help! 我非常感谢你的帮助!

I presume you tried with setting Target Platform (Build option in project properties)? 我假设您尝试设置Target Platform(项目属性中的Build选项)? Also, take a look at this article: http://www.codeproject.com/Articles/383138/BadImageFormatException-x86-i-x64 另外,看看这篇文章: http//www.codeproject.com/Articles/383138/BadImageFormatException-x86-i-x64

I got the same issue on my application. 我在申请时遇到了同样的问题。 It was fixed after I perform the following: 我执行以下操作后修复了它:

* Granting permission for the "Anonymous" user in my web site folder. *授予我的网站文件夹中“匿名”用户的权限。
* Changing the application pool from ".NET v4.5 Classic" to ".NET v4.5". *将应用程序池从“.NET v4.5 Classic”更改为“.NET v4.5”。

All I can offer is some help in determining what isn't loading. 我所能提供的只是帮助确定什么是无法加载。 If it's a dev server it might be worthwhile to install the appropriate sdk to use the Fusion Log Viewer . 如果它是开发服务器,则安装适当的sdk以使用Fusion Log Viewer可能是值得的。 If that isn't an option you can turn on assembly binding logging from the registry as follows: 如果这不是一个选项,您可以从注册表打开程序集绑定日志记录,如下所示:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"LogFailures"=dword:00000001
"LogPath"="c:\\bindFailureLogs\\"

just be sure to turn it off when you're done, there is a performance penalty using the assembly bind logging. 只需确保在完成后将其关闭,使用程序集绑定日志记录会降低性能。 Make sure the folder exists before you enter the registry key and recycle the application pool of the application for the logging to start. 在输入注册表项并重新启动应用程序的应用程序池以启动日志记录之前,请确保该文件夹存在。 This will provide you a detailed list of what dll (or dependency since it's not always readily apparent if it's a dependancy or the dll listed in the error message) didn't load and where it tried to load it from. 这将为您提供详细的列表,列出了什么dll(或依赖项,因为它不是很明显,如果它是一个依赖项或错误消息中列出的dll)没有加载它尝试从中加载它。

Your partitioning of the applications fixing the problem suggests that there are multiple dependencies on the assembly targeting different versions and since only a single version of an assembly can be loaded into an app domain some dependency isn't being satisfied. 您修复问题的应用程序的分区表明,针对不同版本的程序集存在多个依赖关系,并且由于只能将单个版本的程序集加载到应用程序域中,因此不满足某些依赖关系。 For managed assemblies you could use an assembly binding redirect , but I don't know what the unmanaged equivalent of that would be if it even exists. 对于托管程序集,您可以使用程序集绑定重定向 ,但我不知道如果它存在,那将是非托管等效项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.BadImageFormatException: '无法加载文件或程序集 - System.BadImageFormatException: 'Could not load file or assembly 无法加载文件或程序集(BadImageFormatException和FileNotFoundException) - Could not load file or assembly (BadImageFormatException and FileNotFoundException) 无法加载文件或程序集...尝试加载格式不正确的程序 (System.BadImageFormatException) - Could not load file or assembly... An attempt was made to load a program with an incorrect format (System.BadImageFormatException) 无法加载文件或程序集...尝试加载格式不正确的程序 (System.BadImageFormatException) - Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException) BadImageFormatException 无法加载文件或程序集或其依赖项之一。 试图加载格式不正确的程序 - BadImageFormatException Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format System.BadImageFormatException:尝试使用installutil.exe安装服务时无法加载文件或程序集...格式不正确 - System.BadImageFormatException:Could not load file or assembly … incorrect format when trying to install service with installutil.exe System.BadImageFormatException:无法加载文件或程序集-仅在托管服务器上发生异常? - System.BadImageFormatException: Could not load file or assembly- Exception only on hosting server? IIS-system.badimageformatexception无法加载文件或程序集 - IIS - system.badimageformatexception could not load file or assembly 未处理的异常:System.BadImageFormatException:无法加载文件或程序集 - Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 无法加载文件或程序集“ xxxLib”或其依赖项之一。 BadImageFormatException - Could not load file or assembly 'xxxLib' or one of its dependencies. BadImageFormatException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM