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… )

34 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! :)

ade says 17 March 2010 @ 17:40

ah yes, thanks, that was it.

Lernkurve says 1 July 2010 @ 14:30

Thank you!

Andr says 29 July 2010 @ 00:20

Thank you, great and kind man!!!

Eugen says 31 July 2010 @ 14:45

Great!!! Thank you

Antoine says 3 August 2010 @ 13:09

One more day saved ! Thx !

John says 6 August 2010 @ 12:04

Dude – saved my bacon

Haplo says 22 September 2010 @ 16:51

Awesome, thx for this man

Sandesh says 28 October 2010 @ 12:18

Thank you
this worked

amigo says 3 November 2010 @ 10:10

comigo nao funcionou
fodassse

Ulfar Linnet says 14 January 2011 @ 12:26

Greatings from Iceland. You saved me!

Honza says 21 January 2011 @ 16:09

Well I’m happy for you guys, it seems I’m the only one whom this little trick did’t help :o ( Any other ideas?

jagudelo2us says 14 April 2011 @ 19:27

It worked for me. Thank you. Changed in configuration manager from “Any CPU” to “x86″

Kovács Hunor says 14 May 2011 @ 15:04

THANK YOU VERY MUCH!!!!

Matteo Beretta says 20 July 2011 @ 11:34

thank you very much!!
Now I return to live ;)

Ram says 28 July 2011 @ 22:31

Thanks a bunch buddy… Saved a day… :)

Ravindra says 16 August 2011 @ 10:53

Thank you very much it worked for me….You saved my time.

Sheetal Kumar says 16 September 2011 @ 16:49

Go in site and set “enable 32 bit mode” to true. By default it is false in 64 bit OS.

Jens Hamann says 23 November 2011 @ 11:50

Thank you for this post!

lakshmi says 22 March 2012 @ 12:01

Fixed my issue.Thanks for saving my time.

Leave a Comment

Name

E-mail (not published)

Website

Your comment:


  •  

    January 2008
    M T W T F S S
    « Dec   Mar »
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • Categories