This documentation is archived and is not being maintained.

Troubleshooting Exceptions: System.BadImageFormatException 

A BadImageFormatException exception is thrown when the file image of a DLL or executable program is not valid.

Make sure the file image is a valid managed assembly or module.

This exception is thrown when unmanaged code is passed to Load for loading.

For more information, Visual Basic users can see Troubleshooting Interoperability (Visual Basic).

Make sure you have supplied a correct file path for the assembly.

If using a relative path, verify that the current directory is correct.

Reflecting on C++ executable files may throw this exception. This is most likely caused by the C++ compiler stripping the relocation addresses or the .Reloc section from the executable file. To preserve the .relocation address in a C++ executable file, specify /fixed:no when linking.