locked
BadImageFormatException in Net 2.0/32-bit app under Vista/64-bit RRS feed

  • Question

  • Hello,

    I have an app that has been developed and tested under .Net 2.0/VS 2005 and Windows XP (32-bit). Now we are trying to get it up to speed with Vista using VS 2008 and we are running into some issues when running in 64-bit platforms.

    The app uses some 3rd party libraries for widgets and other stuff. Some of those libraries are available in 32-bit for now, so the solution we are looking for is getting to run Vista/64bit with the app targeted to 32-bits. When I target Any CPU, the app runs fine but some of the GUI parts that use our 3rd party library show messed up. If I target x86, those issues are fixed, but the app only runs on Vista/64bit if compiled for debug mode. If I compile the app for release mode I get the following error: 

    System.BadImageFormatException was unhandled
    Message: Could not load file or assembly 'xxx.xxx, Version=xxx, Culture=neutral, PublicKeyToken=xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    An app targeted for x86 is supposed to be able to run in Vista/64bit or not? Why am I able to run it in debug mode? Any ideas on what could I try to figure out this problem? The Exception is not very informative.

    Thanks!
    Friday, June 6, 2008 9:50 PM

Answers

  •  

    (System.BadImageFormatException was unhandled)

    That exception is usually fixed with x86 build so you need to look at the third party ddls to see if any goes back to 16bits.  The other option is to build with x86 in XP because the build options are VS2005/8 edition dependent so build it in XP and deploy the application in WOW64 of the Vista box.  And the AnyCPU build option problems may not be fixed easily because if you get x64 version of the dll and if what you are developing in .NET does not support x64 then you still need to build x86.  The reason most applications build correctly with AnyCPU without third party dlls.


    An Elliptic curve is modular ~ Taniyama and Shimura
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 3:37 AM
    Saturday, June 7, 2008 3:14 PM
    Moderator

All replies

  •  

    (System.BadImageFormatException was unhandled)

    That exception is usually fixed with x86 build so you need to look at the third party ddls to see if any goes back to 16bits.  The other option is to build with x86 in XP because the build options are VS2005/8 edition dependent so build it in XP and deploy the application in WOW64 of the Vista box.  And the AnyCPU build option problems may not be fixed easily because if you get x64 version of the dll and if what you are developing in .NET does not support x64 then you still need to build x86.  The reason most applications build correctly with AnyCPU without third party dlls.


    An Elliptic curve is modular ~ Taniyama and Shimura
    • Marked as answer by Bruno Yu Thursday, June 12, 2008 3:37 AM
    Saturday, June 7, 2008 3:14 PM
    Moderator
  • Well, your app is still running in 64-bit mode.  Use Corflags.exe and verify that the 32BIT flag is turned on.
    Hans Passant.
    • Proposed as answer by Bruno Yu Thursday, June 12, 2008 3:38 AM
    Saturday, June 7, 2008 8:08 PM
    Moderator