visual studio and 64-bit windows (x64)

After moving over to the 64-BIT edition of Windows Vista, I encountered problems with Visual Studio 2005.

The first problem was to do with the Visual Studio window not redrawing itself when an executed application had finished running and VS did not have focus.

The second, and most annoying problem was with external libraries, as I couldn't continue development of some projects because of it. Thankfully, I was able to work out how to fix all of the problems except for one. It's just a shame that it took me months to re-visit the problem as development suffered for it.

When trying to use an ActiveX DLL, DirectX, or other library within Visual Studio, an exception occurs during runtime of either BadImageFormat exception, a Type Initializer exception, or something equally baffling. Why does this happen and how is it fixed? Read on, why don'cha?

When a .NET application that has been compiled to run with the Any CPU configuration and it's running on an x64 host, the application will try to load 64-BIT versions of any libraries that it requires, even if those libraries are in the 32-BIT format. When this mis-match occurs, it throws the BadImageFormat exception.

How is this fixed?

To fix this, you will need to explicitly set the main project's (the Windows Application) configuration to target the 32-BIT platform. The project will now attempt to load the 32-BIT versions of all dependant libraries.

This is a less than optimal solution as it breaks processor optimisations, but it is the only way I know of getting around this application-breaking problem.

Please note that the above explanation is my interpretion of the problem as opposed to the problem as reported by an official source.

If you have any further information on this problem, then feel free to post a comment (if available) and I'll update this posting.

Posted: 2007-10-07 at 16:17:30,