A Confused Programmer's Blog

This blog is dedicated to C# and Java programming that I happen to do for living – with accent on curious cases and with sincere intent to make the world of coding a slightly better place as a result

How to fix BadImageFormatException on x64 platform

I run Windows7 x64 operating system and referencing some of the projects resulted in “BadImageFormatException: could not load file or assembly” error during the run-time.


Microsoft has a knowledge base article explaining that the most likely cause for this error is platform incompatibility.

This behavior will also occur if your application is compiled targeting the "AnyCPU" platform, and then is run an operating system whose platform differs than the assembly whose type you are trying to instantiate. For example, if the main application is compiled to "AnyCPU", and references an assembly that targets x86, then if you run the application on an x64 operating system, the BadImageFormatException will occur.

Although none of the my referenced projects were compiled explicitly as ‘x86’ or ‘x64’ (all were ‘any CPU’), I decided to specify the target platform explicitly as ‘x86’ and it worked. In order to change the target platform, you should go to your project properties inside the Visual Studio and edit ‘Build’ tab:

fix target

Hope the screenshots help.

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

REST Assured and une

If you stumbled onto this article, it is safe to ...

Getting rid of Error

Since I upgraded my Windows 8 to Windows 10, I ...

Bypassing EULA step

We are working on automated testing of virtual appliance. This appliance ...

How I got rid of "Ac

OVF is a VMware virtual appliance format which allows you ...

My use-case of Perfo

In my blog I am set on a mission to ...

Twitter updates

RSS not configured