public class BadImageFormatException : SystemException
Object
Exception
SystemException
BadImageFormatException
mscorlib
RuntimeInfrastructure
Represents the error that occurs when an attempt is made to load a Assembly from a file with an invalid file image.
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.
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.
System Namespace
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
public BadImageFormatException();
Constructs and initializes a new instance of the BadImageFormatException class.
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
.
System.BadImageFormatException Class, System Namespace
public BadImageFormatException(string message);
Constructs and initializes a new instance of the BadImageFormatException class.
- 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.
This constructor initializes the System.BadImageFormatException.Message property of the new instance using message. If message isnull
, 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
.
System.BadImageFormatException Class, System Namespace
public BadImageFormatException(string message, Exception inner);
Constructs and initializes a new instance of the BadImageFormatException class.
- 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 .
This constructor initializes the System.BadImageFormatException.Message property of the new instance using message and the System.BadImageFormatException.InnerException property using inner. If message isnull
, 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.]
System.BadImageFormatException Class, System Namespace
public BadImageFormatException(string message, string fileName);
Constructs and initializes a new instance of the BadImageFormatException class.
- 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.
This constructor initializes the System.BadImageFormatException.Message property of the new instance using message and the System.BadImageFormatException.FileName property using fileName . If message isnull
, 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 tonull
, 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.
System.BadImageFormatException Class, System Namespace
public BadImageFormatException(string message, string fileName, Exception inner);
Constructs and initializes a new instance of the BadImageFormatException class.
- 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 .
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 isnull
, 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 tonull
, 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.
]
System.BadImageFormatException Class, System Namespace
public override string ToString();
Returns a String representation of the value of the current exception.
A String representation of the current exception.
The string representation returned by this method includes the name of the exception, the value of the System.BadImageFormatException.Message property, the result of callingToString
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 isnull
, its value is not included in the returned string.[Note: This method overrides System.Exception.ToString .]
System.BadImageFormatException Class, System Namespace
public string FileName { get; }
Gets the name of the file with the invalid image.
A String containing the name of the file with the invalid image, ornull
if no file name was passed to the constructor for the current instance.
This property is read-only.
System.BadImageFormatException Class, System Namespace
public override string Message { get; }
Gets a String that describes the error that caused the current exception.
A String containing the error 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 notnull
, the message includes the file name.This property is read-only.
System.BadImageFormatException Class, System Namespace