An attempt was made to load a program with an incorrect format. Exception from HRESULT: 0x8007000B (BadImageFormatException)

Note: I assume you can rebuild the program you are having problems with because changes in its configuration settings are required.

If you are struggling with this problem you are probably running 64bit OS and executing 64bit exe that loads 32bit dll, or the other way – 32bit OS on which 32bit exe tries loading 64bit dll. For the sake of this post, let’s assume this is the former matter.

Solution

You need to assure that 32bit dll is loaded by the program with the same bittness, even if it’s running on 64bit platform.

In order to achieve that you need to change the configuration settings of the project whose outcome is that exe so that platform target is always x86, disregarding configuration platform. Let’s assume that program is written in C#.

Open project’s properties, go to Build tab and make change as below:

cs project settings 350x140 An attempt was made to load a program with an incorrect format. Exception from HRESULT: 0x8007000B (BadImageFormatException)

13 Responses to “An attempt was made to load a program with an incorrect format. Exception from HRESULT: 0x8007000B (BadImageFormatException)”


  • Hi,
    I have same error,
    and i make your solution to my app.
    But same error is continue.

  • Salihb,

    You might be referencing the other libraries with bitness that does not match the required.

    If that’s the case you need to prepare two sets of libraries – one for 32bit and one for 64.

    Then configure your project to use either that matches current platform settings.

    Jarek

  • Do you recognize Windows Live? Or Games for Windows Live? Well if you do, I need help with this error.
    The game that uses this program (is it a program?) work perfectly. I can not start the Window Live program ITSELF. It will say, “Can’t start this program. An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) I’m not exactly TECH savvy so…

  • Jarku, you writed:

    “Salihb,

    You might be referencing the other libraries with bitness that does not match the required.

    If that?s the case you need to prepare two sets of libraries ? one for 32bit and one for 64.

    Then configure your project to use either that matches current platform settings.

    Jarek”

    Can you write any tutorial how to make in Visual Studio application, which uses two (x86 and 64 bit) .dll files?

  • Dagna,

    I’m sure there are plenty of instructions on how to do it on the internet :) If you can’t find one though, drop me a note – I’d then need to find a moment and prepare such a guide.

    Cheers,
    Jarek

  • Install 64 bit oralce client
    set access rights to IIS user
    restart System.

  • This error can also occur on “yield return” statements under certain conditions;

    http://connect.microsoft.com/VisualStudio/feedback/details/356858/badimageformatexception-on-movenext-in-templated-yield-based-method-with-expression-used-in-method-body

    the comments section appears to suggest this bug has been fixed, but I’m still getting a similar problem in the .NET 4.0 framework

  • Thanks, worked great!

  • Thanks , It made my day :) . I spent a whole day to fix this..

  • JustAnotherProgrammer

    Thank you for posting the information. Just being able to interpret the error message was enough for me to solve the problem on my own and actually make a deadline that was on the same day. Errors can be tricky to read sometimes huh :)

  • Thanks!! Exactly what I was looking for. Worked perfectly!

  • Thanks Jarosław, this gave me the guideline to solve my problem.

  • Thank you for posting the information.

Leave a Reply