Export (0) Print
Expand All

Troubleshooting Exceptions: System.BadImageFormatException

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

If your application uses 32-bit components, make sure that it always runs as a 32-bit application.

If the Platform target property for your application project is set to AnyCPU, the compiled application can be run in either 64-bit or 32-bit mode. When it runs as a 64-bit application, the just-in-time (JIT) compiler produces 64-bit native code. If the application depends on a 32-bit managed or unmanaged component, that component will fail to load in 64-bit mode. To correct this problem, set the project's Platform target property to x86 and recompile.

Make sure that you are not using a component that was created with a different version of the .NET Framework.

This exception is thrown when an application or component that was developed by using the .NET Framework 1.0 or the .NET Framework 1.1 attempts to load an assembly that was developed by using the .NET Framework 2.0 SP1 or later, or when an application that was developed by using the .NET Framework 2.0 SP1 or the .NET Framework 3.5 attempts to load an assembly that was developed by using the .NET Framework 4. The BadImageFormatException exception may be reported as a compile-time error, or the exception may be thrown at run time. See the BadImageFormatException class for an example.

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

This exception is thrown when an unmanaged dynamic link library or executable is passed to the Load method for loading.

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

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.

For more causes of this exception, see the BadImageFormatException class.

Show:
© 2014 Microsoft