System.BadImageFormatException Class

public class BadImageFormatException : SystemException

Base Types

Object
  Exception
    SystemException
      BadImageFormatException

Assembly

mscorlib

Library

RuntimeInfrastructure

Summary

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

Description

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(System.String) for loading.

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

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.

See Also

System Namespace

Members

BadImageFormatException Constructors

BadImageFormatException() Constructor
BadImageFormatException(System.String) Constructor
BadImageFormatException(System.String, System.Exception) Constructor
BadImageFormatException(System.String, System.String) Constructor
BadImageFormatException(System.String, System.String, System.Exception) Constructor

BadImageFormatException Methods

BadImageFormatException.ToString Method

BadImageFormatException Properties

BadImageFormatException.FileName Property
BadImageFormatException.Message Property


BadImageFormatException() Constructor

public BadImageFormatException();

Summary

Constructs and initializes a new instance of the BadImageFormatException class.

Description

This constructor initializes the System.BadImageFormatException.Message property of the new instance to a system-supplied message that describes the error, such as "Format of the executable or library is invalid." This message takes into account the current system culture.

The System.BadImageFormatException.InnerException and the System.BadImageFormatException.FileName properties of the new instance are initialized to null .

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException(System.String) Constructor

public BadImageFormatException(string message);

Summary

Constructs and initializes a new instance of the BadImageFormatException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

Description

This constructor initializes the System.BadImageFormatException.Message property of the new instance using message. If message is null , the System.BadImageFormatException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.BadImageFormatException.InnerException and the System.BadImageFormatException.FileName properties of the new instance are initialized to null .

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException(System.String, System.Exception) Constructor

public BadImageFormatException(string message, Exception inner);

Summary

Constructs and initializes a new instance of the BadImageFormatException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
inner
An instance of Exception that is the cause of the current exception. If inner is non-null, then the current exception was raised in a catch block handling inner .

Description

This constructor initializes the System.BadImageFormatException.Message property of the new instance using message and the System.BadImageFormatException.InnerException property using inner. If message is null , the System.BadImageFormatException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.BadImageFormatException.FileName property of the new instance is initialized to null .

[Note: For more information on inner exceptions, see System.Exception.InnerException.]

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException(System.String, System.String) Constructor

public BadImageFormatException(string message, string fileName);

Summary

Constructs and initializes a new instance of the BadImageFormatException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
fileName
A String containing the name of the file with the invalid image.

Description

This constructor initializes the System.BadImageFormatException.Message property of the new instance using message and the System.BadImageFormatException.FileName property using fileName . If message is null , the System.BadImageFormatException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.BadImageFormatException.InnerException property of the new instance is initialized to null .

If the fileName parameter is null , the System.BadImageFormatException.FileName property is set to null , the System.BadImageFormatException.Message property does not contain the name of the file, and the System.BadImageFormatException.ToString method does not return the name of the file with the invalid image.

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException(System.String, System.String, System.Exception) Constructor

public BadImageFormatException(string message, string fileName, Exception inner);

Summary

Constructs and initializes a new instance of the BadImageFormatException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
fileName
A String containing the name of the file with the invalid image.
inner
An instance of Exception that is the cause of the current exception. If inner is non-null, then the current exception was raised in a catch block handling inner .

Description

This constructor initializes the System.BadImageFormatException.Message property of the new instance using message, the System.BadImageFormatException.InnerException property using inner, and the System.BadImageFormatException.FileName property using fileName. If message is null , the System.BadImageFormatException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

[Note: If the fileName parameter is null , the System.BadImageFormatException.FileName property is set to null , the System.BadImageFormatException.Message property does not contain the name of the file, and the System.BadImageFormatException.ToString method does not return the name of the file with the invalid image.

For more information on inner exceptions, see System.Exception.InnerException.

]

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException.ToString Method

public override string ToString();

Summary

Returns a String representation of the value of the current exception.

Return Value

A String representation of the current exception.

Description

The string representation returned by this method includes the name of the exception, the value of the System.BadImageFormatException.Message property, the result of calling ToString on the inner exception, the value of the System.BadImageFormatException.FileName property, and the result of calling System.Environment.StackTrace. If any of these members is null , its value is not included in the returned string.

[Note: This method overrides System.Exception.ToString .]

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException.FileName Property

public string FileName { get; }

Summary

Gets the name of the file with the invalid image.

Property Value

A String containing the name of the file with the invalid image, or null if no file name was passed to the constructor for the current instance.

Description

This property is read-only.

See Also

System.BadImageFormatException Class, System Namespace

BadImageFormatException.Message Property

public override string Message { get; }

Summary

Gets a String that describes the error that caused the current exception.

Property Value

A String containing the error description.

Description

If no message was supplied to the constructor for the current exception, this property returns a system-supplied error message. If the System.BadImageFormatException.FileName property is not null , the message includes the file name.

This property is read-only.

See Also

System.BadImageFormatException Class, System Namespace