TypeLoadException.TypeName Propriété

Définition

Obtient le nom complet du type qui lève l’exception.

public:
 property System::String ^ TypeName { System::String ^ get(); };
public string TypeName { get; }
member this.TypeName : string
Public ReadOnly Property TypeName As String

Valeur de propriété

String

Nom complet du type.

Exemples

L’exemple suivant tente de charger un type inexistant à partir de l’assembly mscorlib. L’exception résultante est interceptée et les TypeName Message valeurs sont affichées. Pour que cet exemple de code s’exécute, vous devez fournir le nom complet de l’assembly. Pour plus d’informations sur l’obtention du nom complet de l’assembly, consultez Noms d’assembly.

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

Notes pour les héritiers

En cas de TypeName substitution dans une classe dérivée, veillez à appeler la propriété de la classe de TypeName base.

Cette propriété est en lecture seule.

S’applique à