Click here to Skip to main content
13,588,580 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 9 Nov 2013
Licenced CPOL

Visual Studio 2010: BadImageFormatException was Unhandled

, 9 Nov 2013
Rate this:
Please Sign up or sign in to vote.
BadImageFormatException was unhandled in Visual Studio 2010


Recently, I was cleaning up some code by refactoring a bunch of similar code into a common utility class library project and when I went to debug my first attempt, I got the following error:


This was frustrating because all I did was take a static method in its entirety from one project to another, something I’ve done a thousand times before. On a whim, I tried running the exact same code in Release mode and it ran just fine.  So what I was trying to do was legit, I had an odd configuration mode issue.

After a little research, I found the culprit. Viewing the properties on the new class library project and also the console application, I found that someone on my team had changed the platform target to be x86 instead of “Any CPU”.  Some of the references that I added for the class library were built for other platforms.  After changing the platform target to “Any CPU”, it worked just fine.


There were several only resources that I found saying to change the platform target and be done with it, in this case it worked for me however I wanted to point out one thing.  As a convention, I typically set the Platform for all of my projects to Any CPU so it is as portable as possible however there are cases where you cannot simply change the platform.  As an example:


This is the Configuration Manager found when you right click on the Solution itself.  You will notice that three of the projects in the solution have a Platform defined as x86 and the active solution platform for the Debug configuration is set to “Mixed Platforms”.  In this case, these three projects cannot run on x64 because of the project requirements.

So keep in mind that even though you may read elsewhere that Any CPU is always the answer, you need to look at your environment and the project requirements to make sure it does work.  So even though I normally use Any CPU as well, it is not always the right answer for every project.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

JJ Bussert
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionRoman Badillo Pin
Member 109456014-Nov-14 8:04
memberMember 109456014-Nov-14 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.180615.1 | Last Updated 9 Nov 2013
Article Copyright 2013 by JJ Bussert
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid