Alternate cause of BadImageFormatException in .NET Assembly?

Posted by Phillip Knauss on Stack Overflow See other posts from Stack Overflow or by Phillip Knauss
Published on 2010-03-22T17:51:49Z Indexed on 2010/03/22 18:31 UTC
Read the original article Hit count: 395

I'm working on a .NET 3.5 console application in C# which uses a VC++ unmanaged DLL. It ran without a problem when I worked on it a few weeks ago, but I'm coming back to it today and am now getting a BadImageFormatException ("An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)).

My development workstation is running 64bit Windows 7, and I do a fair amount of work with unmanaged code, so I immediately checked that the .NET assembly and the VC++ library both had x86 targets. They did.

Just to be sure, I cleaned and rebuilt the VC++ library and the .NET assembly, to no avail.

Neither system is doing anything particularly unusual. The VC++ library loads a binary data file and does some mathematical processing on its contents. The .NET assembly has the DllImports for the library and some code to wire it up. This all worked a few weeks ago.

So now I'm left wondering if there's some other cause of BadImageFormatException that's less common than an x86/x64 conflict that I might be running into.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about c++