BadImageFormatException when loading 32 bit DLL, target is x86

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.

Leave a Comment