Partager via


Troubleshooting Exceptions: System.BadImageFormatException 

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

Associated Tips

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

Remarks

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.

See Also

Tasks

How to: Find Out More About an Exception with the Exception Assistant

Reference

Visual J# Exception Handling for the Debugger
Visual J# Exception Hierarchies
BadImageFormatException