Export (0) Print
Expand All

TypeLoadException.Message Property

Gets the error message for this exception.

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

public override string Message { get; }

Property Value

Type: System.String
The error message string.

Implements

_Exception.Message

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 Assembly Names.

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.'
 */

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft