Export (0) Print
Expand All

TypeLoadException.TypeName Property

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

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

public string TypeName { get; }
/** @property */
public String get_TypeName ()

public function get TypeName () : String

Property Value

The fully qualified type name.

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.

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft