Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TypeLoadException.Message Property

Gets the error message for this exception.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public override string Message { get; }
/** @property */
public String get_Message ()

public override function get Message () : String

Not applicable.

Property Value

The error message string.

This property overrides Message. The error message should be localized.

This property is read-only.

The following example attempts to load a non-existent type from the mscorlib assembly. The resulting exception is caught, and the TypeName and Message values are displayed. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [<topic://cpconassemblynames>].

using System;
using System.Reflection;

public class TypeLoadException_TypeName
{
   public static void Main() 
   {
      // Get a reference to the assembly mscorlib.dll, which is always
      // loaded. (System.String is defined in mscorlib.)
      Assembly mscorlib = typeof(string).Assembly;

      try 
      {
         Console.WriteLine("Attempting to load a type that does not exist in mscorlib.");
         // The boolean parameter causes an exception to be thrown if the
         // type is not found.
         Type myType = mscorlib.GetType("System.NonExistentType", true);
      }  
      catch (TypeLoadException ex) 
      {
         // Display the name of the type that was not found, and the 
         // exception message.
         Console.WriteLine("TypeLoadException was caught. Type = '{0}'.", 
             ex.TypeName);
         Console.WriteLine("Error Message = '{0}'", ex.Message);
      }  
   }
}
/*
 This code example produces output similar to the following:

Attempting to load a type that does not exist in mscorlib.
TypeLoadException was caught. Type = 'System.NonExistentType'
Error Message = 'Could not load type System.NonExistentType from assembly mscorl
ib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.'
 */

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft