TypeLoadException.TypeName Property
Gets the fully qualified name of the type that causes the exception.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
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 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.