Hopefully this helps some of you.
I am currently running Windows XP-64 ,and "BadImageFormatException" was a new one for me. It appears that the underlying calls via PInvoke to some of the currently referenced external libraries are 32-bit. What had me puzzled for
a little while was that under Visual Studio 2008, the entire solution that I had created would build successfully. Yet, at runtime I would consistently get the "BadImageFormatException" error.
Well, thanks to the Internet, I discovered the answer. Currently, If you are performing development on 64-bit systems, you need to force 32-bit compilation on all of the referencing projects.
Why? More than likely this has to do with 32-bit vs. 64-bit addressing (speculation on my part). If someone could please either confirm or refute this, it would be appreciated.
This can be achieved at least one of two ways:
Visual Studio 2008: Project Properties Dialog/Build Tab/Platform target needs to be set to x86.
If using makefiles, or compiling outside Visual Studio, the "/platform:x86" compilation switch will achieve the same goal.
From some research, this may also be occurring on other 64-bit Windows platforms of more recent vintage(Vista,Windows 7).
For future consideration, I might be worth considering targeting both 32 and 64 bit systems as the 64 bit systems are becoming more prevalent in the market.