Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.BadImageFormatException: How to fix .NET version mismatch?

I wrote a dll in VS 2005 that will be loaded by another program that was developed in VS 2003. When that program tries to load my dll, it throws a System.BadImageFormatException: The format of the file 'Foo.dll' is invalid.

I searched SO and Google, and it seems that the different version of .NET is the culprit. My question is: How do I fix this?

(I cannot modify the program developed in VS 2003.)

like image 252
joshdick Avatar asked May 05 '09 17:05

joshdick


People also ask

How do I resolve system Badimageformatexception?

Solution 1Try compiling to 32bit by changing project properties/Build/Platform Target .

Could not load file or assembly 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.


3 Answers

I got this error when I was running the 64bit version of the CLR and trying to load an assembly that was marked 32bit only. The specific assembly in my case was the Oracle.DataAccess.dll that comes as part of ODP.NET.

like image 108
John Downey Avatar answered Oct 15 '22 19:10

John Downey


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.

like image 44
bluwater2001 Avatar answered Oct 15 '22 19:10

bluwater2001


Compile the VS2005 Project with the same .Net Version as your VS2003 Project uses. Or, depending of the size of your VS2003 Project, reflector and rewrite it. That's common practice for projects over here, where for some obscure reason there is no more VSS version available.

like image 22
Markus Nigbur Avatar answered Oct 15 '22 19:10

Markus Nigbur