Mono Class Library: System Namespace

System.BadImageFormatException Class

Represents the error that occurs when an attempt is made to load a System.Reflection.Assembly from a file with an invalid file image. [Edit]

See Also: BadImageFormatException Members

System.Object
     System.Exception
          System.SystemException
               System.BadImageFormatException

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

Thread Safety

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

Remarks

This exception is thrown when the file image of an executable program is invalid. For example, this exception is thrown when unmanaged code is passed to System.Reflection.Assembly.Load(string) for loading. [Edit]

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