Getting BadImageFormatException in 64-bit Windows?
17 January 2008 in .NET in general & Code-ing | Comments enabled
Have you been running/developing .NET programs in 64-bit Windows and met the BadImageFormatException? Well, Microsoft might say: “The exception that is thrown when the file image of a DLL or an executable program is invalid.” Which says absolutely nothing…
However, if it happens when using Platform Invove (P/Invoke or DllImport) or a third .NET party library (DLL) then you might have to set the project’s properties (or compilation flags) from “any” platform target to “x86″. Also, remember to set change to x86 in both the debug and release build configurations while you are at it, otherwise it might seem to only work when you are debugging and not in release compilation.
(This happened to me when I used a .NET code library for a LabJack device in a program and ran the program under 64-bit Vista. Couldn’t find what the nature of the problem “really” was… )
15 comments. Add your own comment.
JS says 12 June 2008 @ 22:24
Thanks! It fixed the problem.
frenchfaso says 27 October 2008 @ 23:53
OhHo! You’re the man…
thank You so much, I could’nt compile examples of Brahma (http://brahma.ananthonline.net) until I read your post.
Paulie says 6 November 2008 @ 18:07
Worked for me too. Cheers
babu says 4 December 2008 @ 17:03
Thank you! Saved my day.
Wallace says 18 December 2008 @ 17:23
Thank you! You really saved my day.
Norbert says 2 January 2009 @ 20:06
Thanks. I had a test project with “any” platform target build against a lib with “x86″ target. After changing to “x86″, the exception disappeared.
Thanks for that, otherwise I would have started 2009 unhappily…
ulothix says 6 January 2009 @ 21:45
Yeah, thanks a lot!
Alex says 21 January 2009 @ 01:23
Thanks a lot for this, if this wasn’t for this blog post I would still be searching!
Abhishek Mishra says 9 February 2009 @ 18:10
Thanks, saved me from loads of confusions
Sameers says 20 April 2009 @ 17:14
Well, I got the same issue (actually complaint). My first intention was the same as you wrote, I tried that and it fixed that.
Thanks for sharing your experience anyway,
Sameers
Matt says 23 April 2009 @ 19:38
Yup, saved me too
Now to find out what is really going on here.
Robert Claypool says 11 May 2009 @ 19:21
Thank you for posting. This saved me considerable time.
Luigie says 4 August 2009 @ 12:20
I’ve the same problem the other way around.
developing on a 32 bit machine and need to deploy on a 64 machine.
I’ve set the project out put ot x64
all the referenced project are set to “Any CPU”
can anyone help me?
tr says 31 December 2009 @ 19:35
really thank you!
Samuel Moura says 26 January 2010 @ 16:34
Thanks a bunch for this!
Leave a Comment