This documentation is archived and is not being maintained.

TypeLoadException.TypeName Property

Gets the fully qualified name of the type that causes the exception.

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

Property Value

The fully qualified type name.

Remarks

Notes to Inheritors:  When overriding TypeName in a derived class, be sure to call the base class's TypeName property.

This property is read-only.

Example

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, Common Language Infrastructure (CLI) Standard

See Also

TypeLoadException Class | TypeLoadException Members | System Namespace

Show: