BadImageFormatException on Windows XP-64

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Jun 26, 2010 at 2:58 PM

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.

Coordinator
Jun 27, 2010 at 9:00 PM

Hello Scottandh,

thanks for this useful explaination. I'd like to add that the only component that relies on x86 platform is the SharpMap.Extensions project, since it relies on native libraries like GDAL/OGR and SpatiaLite. If you don't need these providers you can safely exclude them from build and change the build target back to AnyCPU.

Hth FObermaier