TypeLoadException.Message Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the error message for this exception.
public:
virtual property System::String ^ Message { System::String ^ get(); };
public override string Message { get; }
member this.Message : string
Public Overrides ReadOnly Property Message As String
The error message string.
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.
// Load the mscorlib assembly and get a reference to it.
// You must supply the fully qualified assembly name for mscorlib.dll here.
Assembly^ myAssembly = Assembly::Load( "Assembly text name, Version, Culture, PublicKeyToken" );
try
{
Console::WriteLine( "This program throws an exception upon successful run." );
// Attempt to load a non-existent type from an assembly.
Type^ myType = myAssembly->GetType( "System.NonExistentType", true );
}
catch ( TypeLoadException^ e )
{
// Display the name of the Type that was not found.
Console::WriteLine( "TypeLoadException: \n\tError loading the type '{0}' from the assembly 'mscorlib'", e->TypeName );
Console::WriteLine( "\tError Message = {0}", e->Message );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: Error Message = {0}", e->Message );
}
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.'
*/
Imports System.Reflection
Public Class Example
Public Shared Sub Main()
' Get a reference to the assembly mscorlib.dll, which is always
' loaded. (System.String is defined in mscorlib.)
Dim tString As Type = GetType(String)
Dim mscorlib As [Assembly] = tString.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.
Dim myType As Type = mscorlib.GetType("System.NonExistentType", True)
Catch ex As TypeLoadException
' 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)
End Try
End Sub
End Class
'
' This 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.'
This property overrides Message. The error message should be localized.
This property is read-only.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: