RuntimeInfrastructure mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.SystemException System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates an attempt to load an unmanaged executable, which causes the system to throw a exception. 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.

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:

An earlier version of a .NET Framework utility, such as ILDasm.exe or installutil.exe, is used with an assembly that was developed with a later version of the .NET Framework.

To address this exception, use the version of the tool that corresponds to the version of the .NET Framework that was used to develop the assembly. This may require modifying the Path environment variable or providing a fully qualified path to the correct executable.

An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly. The following example illustrates this by using the method to load Kernel32.dll.

code reference: System.BadImageFormatException.Class#1

To address this exception, access the methods defined in the DLL by using the features provided by your development language, such as the Declare statement in Visual Basic or the attribute with the extern keyword in C#.

A DLL or executable is loaded as a 64-bit assembly, but it contains 32-bit features or resources. For example, it relies on COM interop or calls methods in a 32-bit dynamic link library.

To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.

Components have been created using different versions of the .NET Framework. Typically, this exception occurs when an application or component that was developed using the net_v10_short or the net_v11_short attempts to load an assembly that was developed using the net_v20SP1_short or later, or when an application that was developed using the net_v20SP1_short or net_v35_short attempts to load an assembly that was developed using the net_v40_short. The may be reported as a compile-time error, or the exception may be thrown at run time. The following example illustrates this scenario. It defines a StringLib class that has a single member, ToProperCase, and that resides in an assembly named StringLib.dll.

code reference: System.BadImageFormatException.Class#2

The following example uses reflection to load an assembly named StringLib.dll. If the source code is compiled with a net_v11_short compiler, a is thrown by the method.

code reference: System.BadImageFormatException.Class#3

To address this exception, ensure that the assembly from which the exception is thrown attempts to load an assembly that was developed by using a compatible version of the .NET Framework.

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

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

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

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the 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 following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The localized error message string.

  Initializes a new instance of the class.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The content of the parameter 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.

  The following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The error message string.

  Initializes a new instance of the class with a specified error message.

  The message that describes the error.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor is called during deserialization to reconstitute the exception object transmitted over a stream.

  Initializes a new instance of the class with serialized data.

  The that holds the serialized object data about the exception being thrown.
  The that contains contextual information about the source or destination.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  The error message string.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The content of the parameter 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.

  Property

  Value

  The full name of the file with the invalid image.

  The error message string.

  Initializes a new instance of the class with a specified error message and file name.

  A message that describes the error.
  The full name of the file with the invalid image.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  The full name of the file with the invalid image.

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  The full name of the file with the invalid image.

  The error message string.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The full name of the file with the invalid image.
  The exception that is the cause of the current exception. If the parameter is not null, the current exception is raised in a catch block that handles the inner exception.
  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

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

  This property returns the name of the file supplied to the constructor for the current instance, if any. If the file name was not specified or is a null reference (Nothing in Visual Basic), this property returns a null reference.

  This property is read-only.

  Gets the name of the file that causes this exception.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String To be added. To be added.

  Gets the log file that describes why an assembly load failed.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added.

  Sets the object with the file name, assembly cache log, and additional exception information.

  The that holds the serialized object data about the exception being thrown. The that contains contextual information about the source or destination.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A 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 property is not a null reference (Nothing in Visual Basic), the message includes the file name.

  This property is read-only.

  Gets the error message and the name of the file that caused this exception.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  The string representation returned by this method includes the name of the exception, the value of the property, the result of calling ToString on the inner exception, the value of the property, and the result of calling . If any of these members is a null reference (Nothing in Visual Basic), its value is not included in the returned string.

  Returns the fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.

  A string containing the fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.

  0
0