Description





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 for loading.

Example

using System;



/// <summary>

/// Attempts to load an executable that is not a valid image

/// Handles the exception and displays the details

/// </summary>



public class BadImageFormatExceptionSample

{

    public static void Main()

    {

        try

        {

            AppDomain domain = AppDomain.CreateDomain("MyNewDomain");

            Console.WriteLine("Attempting to execute BadImage.exe...");

            domain.ExecuteAssembly("BadImage.exe");

        }

        catch (BadImageFormatException bifex)

        {

            Console.WriteLine("BadImageFormatException Thrown ...");

            Console.WriteLine("BadImageFormatException FileName "

                + "= '{0}'", bifex.FileName);

            Console.WriteLine("BadImageFormatException Message "

                + "= '{0}'", bifex.Message);

        }

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }

}


The output is


Attempting to execute BadImage.exe...

BadImageFormatException Thrown ...

BadImageFormatException FileName = 'BadImage.exe'

BadImageFormatException Message = 'The format of the file 'BadImage.exe' is inva

lid.'





Press Enter to continue



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows