Click here to Skip to main content
Click here to Skip to main content

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

Introduction

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:

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.

Location

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:

Recap

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.

License

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

About the Author

JJ Bussert
Architect
United States United States
No Biography provided
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 9 Nov 2013
Article Copyright 2013 by JJ Bussert
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid