System.BadImageFormatException Class

The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.

See Also: BadImageFormatException Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class BadImageFormatException : SystemException

Remarks

This exception is thrown when the file format of a dynamic link library (.dll file) or an executable (.exe file) does not conform to the format that is expected by the common language runtime. In particular, the exception is thrown under the following conditions:

BadImageFormatException uses the HRESULT COR_E_BADIMAGEFORMAT, which has the value 0x8007000B.

For a list of initial property values for an instance of BadImageFormatException, see the BadImageFormatException constructors.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Example

The following example demonstrates an attempt to load an unmanaged executable, which causes the system to throw a BadImageFormatException exception.

Note: The name of the unmanaged executable is "calc".

C# Example

using System;
using System.Reflection;

public class BadImageExample {
  public static void Main() {
    try {
      Assembly a = Assembly.Load("calc");
    } 
    catch (BadImageFormatException e) {
      Console.WriteLine("Caught: {0}", e.Message);
    }
  } 
}
   

The output is

Caught: The format of the file 'calc' is invalid.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0