Weird BadImageFormatException
Late yesterday, my program spit me this error message:
An unhandled exception of type ‘System.BadImageFormatException’ occurred in SomeAwesome.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0×8007000B)
This is rather weird. The program loads properly, yet at some part, it tells me that I’m loading “a program with an incorrect format”? After quite some time searching the net, I found this blog entry explaining it.
I think this is the first time that I was really got bitten by a C# compiler bug. Seems like, in some weird occasion, if you put the constraint where T : class to your generics, some things won’t get compiled properly to IL.
I’m actually loading the class dynamically using the Activator, in a simple dependency injection container that I made. I thought that was the problem. But when I try to load it normally, the same error occurs, even after restarting the machine (yeah, you know, some times things magically work after a reboot). In the end, found out it’s not my fault… finally, something that isn’t.
Trackbacks
Use this link to trackback from your own site.

