BadImageFormatException when loading 32 bit DLL, target is x86
Solution 1:
From what I understand, an assembly specifically built for x86 and running in a 64-bit operating system can only load libraries built for x86 or a BadImageFormatException will be thrown. In a 64-bit OS, an assembly built for Any CPU or x64 will throw the same exception when trying to load an x86 library.
So, assuming nothing incredibly weird is going on, I would ensure that you've set your application to build as x86 by opening the project properties and clicking on the Build tab. Ensure 'Platform Target' is set as 'x86' and not Any CPU.
Alternatively, you could try to find a 64-bit version of the DLL for testing purposes.
Solution 2:
Recompile the dll with the option "Any CPU" in Build -> Platform.
Solution 3:
OK, seems like a false alert. It was not related to bitness, there was just other DLL missing that freetype depends on. However error messages could be more helpful.
Solution 4:
Got the same error when calling a 64-bit C Dll from C#. I had to manually change C# Properties->Build->Platform target
from Any Cpu
to x64
. Apparently Any Cpu
is sometimes NoCpu.
Solution 5:
Besides, for web-application needs resolve to run 32-Bit Applications in IIS 7. See http://www.fishofprey.com/2009/04/badimageformatexception-in-iis-70-on-64.html