Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TypeLoadException.Message Property

Gets the error message for this exception.

[Visual Basic]
Overrides Public ReadOnly Property Message As String
[C#]
public override string Message {get;}
[C++]
public: __property String* get_Message();
[JScript]
public override function get Message() : String;

Property Value

The error message string.

Remarks

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

This property is read-only.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
' Load the mscorlib assembly and get a reference to it.
' You must supply the fully qualified assembly name for mscorlib.dll here.
Dim myAssembly As [Assembly] = [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. 
   Dim myType As Type = myAssembly.GetType("System.NonExistentType", True)
Catch e As TypeLoadException
   ' Display the name of the Type that was not found.
   Console.WriteLine("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "Error loading the type '{0}' from the assembly 'mscorlib'", e.TypeName)
   Console.WriteLine((ControlChars.Tab + "Error Message = " + e.Message))
Catch e As Exception
   Console.WriteLine(("Exception: Error Message = " + e.Message))
End Try

[C#] 
// 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 = " + e.Message);
}  
catch (Exception e) 
{
   Console.WriteLine ("Exception: Error Message = " + e.Message);
}

[C++] 
// 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(S"Assembly text name, Version, Culture, PublicKeyToken");
try {
   Console::WriteLine(S"This program throws an exception upon successful run.");
   // Attempt to load a non-existent type from an assembly. 
   Type*  myType = myAssembly->GetType(S"System.NonExistentType", true);
} catch (TypeLoadException* e) {
   // Display the name of the Type that was not found.
   Console::WriteLine (S"TypeLoadException: \n\tError loading the type '{0}' from the assembly 'mscorlib'", e->TypeName);
   Console::WriteLine (S"\tError Message = {0}", e->Message);
} catch (Exception* e) {
   Console::WriteLine (S"Exception: Error Message = {0}", e->Message);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

TypeLoadException Class | TypeLoadException Members | System Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.