Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BadImageFormatException was unhandled

"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.

like image 654
user2330678 Avatar asked Dec 02 '13 20:12

user2330678


1 Answers

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.

like image 94
Rafael Avatar answered Sep 30 '22 15:09

Rafael