12

"BadImageFormatException" is thrown while compiling or attempting to run my application on Windows 8 64 bit. I've scoured the Internet and many people have the same error message. However, none of the solutions address my problem or situation. I am using Visual Studio 2012 Express.

Error message

Error 38 Could not load file or assembly 'file:///C:/Projects/Windows Projects/Weld/Components/FileAttachments/FileAttachments/FileAttachments/bin/x86/Debug/FileAttaching.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I do have some C++ dlls and most dlls are in C#. Some of the dlls are compiled on 32 bit machines and I am using a 64 bit machine.

2
  • 4
    I've stumbled on this when dll's are compiled 32 and 64 bit (mixed). Are all the dll's compiled the same?
    – gleng
    Dec 2, 2013 at 20:48
  • @gleng I do have some 32 bit and some 64 bit dlls on a 64 bit machine. Thanks will update the question. Dec 2, 2013 at 20:50

1 Answer 1

19

This error BadImageFormatException, always means that you either tried to load a 32 bits DLL into a 64 bits application or that you tried to load a 64 bits DLL into a 32 bits application.

Sometimes this also happens when you compile for AnyCPU, so if you DLLs target an specific platform, you may want to make your project target this specific platform.

In your current scenario, probably FileAttaching.dll is a 64 bits DLL, so I recommend you to check that you're outputting 32 bits DLLs on this project or using the proper 32 bits version.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.