TypeLoadException.Message 속성
이 예외에 대한 오류 메시지를 가져옵니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Overrides ReadOnly Property Message As String
‘사용 방법
Dim instance As TypeLoadException
Dim value As String
value = instance.Message
public override string Message { get; }
public:
virtual property String^ Message {
String^ get () override;
}
/** @property */
public String get_Message ()
public override function get Message () : String
속성 값
오류 메시지 문자열입니다.
설명
이 속성은 Message를 재정의합니다. 오류 메시지는 지역화해야 합니다.
이 속성은 읽기 전용입니다.
예제
다음 예제에서는 mscorlib 어셈블리에서 존재하지 않는 형식을 로드하려고 합니다. 이에 따라 예외가 catch되고 TypeName과 Message 값이 표시됩니다. 이 코드 예제를 실행하려면 정규화된 어셈블리 이름을 사용해야 합니다. 정규화된 어셈블리 이름을 가져오는 방법에 대한 자세한 내용은 어셈블리 이름을 참조하십시오.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
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.'
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.'
*/
// 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 );
}
플랫폼
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
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원