Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BadImageFormatException C# [duplicate]

Tags:

c#

.net

dll

I'm using Visual C# Studio 10.0 with .NET Framework 4.0 and I was trying to load in the SoundTouchSharp library and create an instance of the library (object) in my application. However, after I type in the path for the file, I get this error:

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

How should I fix that? I'm almost positive that I created the .dll using the VS terminal and it should be the same version as the .NET framework. I can also provide more code if needed.

Thanks!

like image 941
m00nbeam360 Avatar asked Apr 10 '13 04:04

m00nbeam360


People also ask

How to fix System badimageformatexception?

SOLUTION: If you are on IIS7, Right Click/ Advanced Settings on the Specific Application Pool of the website and select True on Enable 32-Bit Applications. It should work.

What is Badimageformatexception?

This exception is thrown when the file format of a dynamic link library (. dll file) or an executable (.exe file) doesn't conform to the format that the common language runtime expects.

Could not load an attempt was made to load a program with an incorrect format?

“An attempt was made to load a program with an incorrect format.” That means that the assembly, which was to be loaded, was in an unexpected format. The format, in this case, refers most likely to the 64-bit build of an application being deployed to IIS, which is being run in 32-bits.


1 Answers

Make sure that you are not having 32-bit / 64-bit conflict.

Refer this question:

Troubleshooting BadImageFormatException

If you're running on a 64-bit OS, the Assembly RevitAPI may be compiled as 32-bit and your process as 64-bit or "Any CPU".

Or, the RevitAPI is compiled as 64-bit and your process is compiled as 32-bit or "Any CPU" and running on a 32-bit OS.

like image 66
Freelancer Avatar answered Oct 04 '22 19:10

Freelancer