This documentation is archived and is not being maintained.

Troubleshooting Exceptions: System.BadImageFormatException

Updated: April 2011

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

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

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.




April 2011

Added common causes of the exception.

Customer feedback.