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

joshdick picture joshdick · May 5, 2009 · Viewed 35.3k times · Source

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

Answer

John Downey picture John Downey · May 5, 2009

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.