Derik Whittaker



Incorrect Image Format Error -- x86 vs x64 vs Any CPU

Today I was trying to wrap one of our .dll projects in a wcf endpoint and ran into an odd issue that took 3 hours to resolve and the mad skills of my co-worker James to help resolve.

Long story short, when I would F5 my web project which was hosting our WCF endpoints I would get the following message in the browser.


Of course when I got this I immediately jumped to the referencing project and made sure I had referenced all the needed child assemblies.  When this checked out I then jumped to the BIN folder to make sure they were copied correctly, they were.  When THIS failed I fired up Just Decompile to ensure that the version of the assemblies were right… All of this lead me NO WHERE.

Now that I have done the typical checks I resorted to firing up the Fusion Log viewer with hopes that this would help… Yea that did nothing….

At this point I was beating my head against the desk, this was also the point that I enlisted the skills and knowledge of James.  As we were talking through the problem and looking around we made our way over to the project properties of the dll I was referencing.  When looking over the properties James noticed that my target platform was x86 (seen below),


which immediately sent up the red flag for him (it did nothing for me).  Of course the question of ‘why is this x86’ was asked to which I answered ‘I don’t know’ but I did know the that project was originally a console app project prior to being switched to a library project…. Ding, Ding, Ding….  Console apps are set to x86 by default not Any CPU.

Once we changed it to Any CPU and recompiled my issues were resolved (seen below)


The moral of the story is that if you get the ‘bad image’ error make sure you are not trying to reference an x86 assembly in your x64 projects.

Till next time,

Posted 04-25-2012 10:23 AM by Derik Whittaker
Filed under: , ,



Richard Dingwall wrote re: Incorrect Image Format Error -- x86 vs x64 vs Any CPU
on 04-25-2012 11:50 AM

This can also cause "System.TypeLoadException: Method ... in type ... from assembly ... does not have an implementation." errors.

Martin Costello wrote re: Incorrect Image Format Error -- x86 vs x64 vs Any CPU
on 04-25-2012 4:27 PM

Or indeed, not using x64 DLLs on a x86 computer (yes, some of us still have 32-bit PCs at work...), or referencing a native dependency where the bitness doesn't match.

Rohan Cragg wrote re: Incorrect Image Format Error -- x86 vs x64 vs Any CPU
on 04-26-2012 4:27 AM

There's a really comprehensive explanation here:

And some advice on how to clean up solution/project configs once and for all...

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)