BadImageFormatException: Failed to load file or assembly ... bad format - only with web application

I am working on a web application on a 64-bit Windows 8 machine using several existing libraries. I want to use two C # libraries that reference the same native DLL. Both C # DLLs were compiled for 64-bit use and tested in test applications. My web application references both C # libraries and should run on IIS 8. I added two C # libraries as project references and my own DLL manually to the bin folder in the web application. Whenever I create and run a solution, I get the exception indicated in the header. I know that this is a sign of a problem with 32-bit and 64-bit code running in the same process. Therefore, I tried different build configurations, but the result did not change.

I created a console application that does exactly what I'm trying to use in a web application and it works flawlessly. However, a web application with exactly the same settings throws an exception, this is what really bothers me.

What I have tried so far:

  • Change the application pool setting to "enable 32-bit applications"
  • Build all DLLs with any CPU, 64Bit or x86 target
  • Check flags of all dlls

I can provide export of the project to anyone who wants to help me run this configuration!

I really appreciate every help!

+6
source share
3 answers

I assume that you tried to install the target platform (build option in the project properties)? Also, take a look at this article: http://www.codeproject.com/Articles/383138/BadImageFormatException-x86-i-x64

0
source

I have the same problem in my application. This has been fixed after performing the following steps:

* Granting permission for the user "Anonymous user" in the folder of my website.
* Changing the application pool from ".NET v4.5 Classic" to ".NET v4.5".

0
source

All I can offer is some help in determining what is not loading. If this is a dev server, it might be worth installing the appropriate sdk to use the Fusion Log Viewer . If this is not an option, you can enable 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 remember to turn it off when you are done, there is a performance limitation using assembly binding logging. Make sure the folder exists before you enter the registry key and restart the application's application pool to start registration. This will provide you with a detailed list of what the dll (or dependency, since it is not always obvious if it was dependent or the dll indicated in the error message) did not load and where did it try to load it.

Separating the applications that fix the problem indicates that there are several assembly dependencies for different versions, and since only one version of the assembly can be loaded into the application domain, some dependency is not executed. For managed assemblies, you can use assembly binding redirection , but I don't know what the unmanaged equivalent of this will be, if it even exists.

0
source

All Articles