다음을 통해 공유


MissingMemberException 클래스

존재하지 않는 클래스 멤버에 동적으로 액세스하려고 할 때 throw되는 예외입니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class MissingMemberException
    Inherits MemberAccessException
    Implements ISerializable
‘사용 방법
Dim instance As MissingMemberException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class MissingMemberException : MemberAccessException, ISerializable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class MissingMemberException : public MemberAccessException, ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class MissingMemberException extends MemberAccessException implements ISerializable
SerializableAttribute 
ComVisibleAttribute(true) 
public class MissingMemberException extends MemberAccessException implements ISerializable

설명

일반적으로, 코드에서 존재하지 않는 클래스 멤버에 액세스하려고 하면 컴파일 오류가 발생합니다. MissingMemberException은 한 어셈블리에서 필드 또는 메서드가 삭제되었거나 이름이 바뀌었는데 해당 변경 내용이 두 번째 어셈블리에는 반영되지 않는 경우를 처리하기 위한 것입니다. 런타임에 두 번째 어셈블리의 코드에서 첫 번째 어셈블리의 손실된 멤버에 액세스하려고 하면 MissingMemberException이 throw됩니다.

MissingMemberExceptionMissingFieldExceptionMissingMethodException에 대한 기본 클래스입니다. 일반적으로 MissingMemberException의 파생 클래스 중 하나를 사용하여 해당 오류의 속성을 보다 정확하게 나타내는 것이 좋습니다. 손실된 멤버 오류의 일반적인 경우를 캡처하려면 MissingMemberException을 throw합니다.

MissingMemberException은 0x80131512 값을 가지는 HRESULT COR_E_MISSINGMEMBER를 사용합니다.

MissingMemberException 인스턴스의 초기 속성 값 목록에 대한 자세한 내용은 MissingMemberException 생성자를 참조하십시오.

예제

이 예제에서는 리플렉션을 사용하여 존재하지 않는 메서드를 호출하고 존재하지 않는 필드에 액세스하려고 하는 경우 어떠한 일이 발생하는지 보여 줍니다. 응용 프로그램은 MissingMethodException, MissingFieldExceptionMissingMemberException을 catch하여 복구됩니다.

using System;
using System.Reflection;

public class App 
{
    public static void Main() 
    { 
        
        try 
        {
            // Attempt to call a static DoSomething method defined in the App class.
            // However, because the App class does not define this field, 
            // a MissingFieldException is thrown.
            typeof(App).InvokeMember("DoSomething", BindingFlags.Static | 
                BindingFlags.InvokeMethod, null, null, null);
        }
        catch (MissingMethodException e) 
        {
            // Show the user that the DoSomething method cannot be called.
            Console.WriteLine("Unable to call the DoSomething method: {0}", e.Message);
        }

        try 
        {
            // Attempt to access a static AField field defined in the App class.
            // However, because the App class does not define this field, 
            // a MissingFieldException is thrown.
            typeof(App).InvokeMember("AField", BindingFlags.Static | BindingFlags.SetField, 
                null, null, new Object[] { 5 });
        }
        catch (MissingFieldException e) 
        {
         // Show the user that the AField field cannot be accessed.
         Console.WriteLine("Unable to access the AField field: {0}", e.Message);
        }

        try 
        {
            // Attempt to access a static AnotherField field defined in the App class.
            // However, because the App class does not define this field, 
            // a MissingFieldException is thrown.
            typeof(App).InvokeMember("AnotherField", BindingFlags.Static | 
                BindingFlags.GetField, null, null, null);
        }        
        catch (MissingMemberException e) 
        {
         // Notice that this code is catching MissingMemberException which is the  
         // base class of MissingMethodException and MissingFieldException.
         // Show the user that the AnotherField field cannot be accessed.
         Console.WriteLine("Unable to access the AnotherField field: {0}", e.Message);
        }
    }       
}
// This code produces the following output.
//
// Unable to call the DoSomething method: Method 'App.DoSomething' not found.
// Unable to access the AField field: Field 'App.AField' not found.
// Unable to access the AnotherField field: Field 'App.AnotherField' not found.
using namespace System;
using namespace System::Reflection;

ref class App 
{       
};

int main()
{
    try 
    {
        // Attempt to call a static DoSomething method defined in the App class.
        // However, because the App class does not define this field, 
        // a MissingFieldException is thrown.
        App::typeid->InvokeMember("DoSomething", BindingFlags::Static | 
            BindingFlags::InvokeMethod, nullptr, nullptr, nullptr);
    }
    catch (MissingMethodException^ ex) 
    {
        // Show the user that the DoSomething method cannot be called.
        Console::WriteLine("Unable to call the DoSomething method: {0}", 
            ex->Message);
    }

    try 
    {
        // Attempt to access a static AField field defined in the App class.
        // However, because the App class does not define this field, 
        // a MissingFieldException is thrown.
        App::typeid->InvokeMember("AField", BindingFlags::Static | 
            BindingFlags::SetField, nullptr, nullptr, gcnew array<Object^>{5});
    }
    catch (MissingFieldException^ ex) 
    {
        // Show the user that the AField field cannot be accessed.
        Console::WriteLine("Unable to access the AField field: {0}", 
            ex->Message);
    }

    try 
    {
        // Attempt to access a static AnotherField field defined in the App class.
        // However, because the App class does not define this field, 
        // a MissingFieldException is thrown.
        App::typeid->InvokeMember("AnotherField", BindingFlags::Static | 
            BindingFlags::GetField, nullptr, nullptr, nullptr);
    }        
    catch (MissingMemberException^ ex) 
    {
        // Notice that this code is catching MissingMemberException which is the  
        // base class of MissingMethodException and MissingFieldException.
        // Show the user that the AnotherField field cannot be accessed.
        Console::WriteLine("Unable to access the AnotherField field: {0}", 
            ex->Message);
    }
}
// This code produces the following output.
//
// Unable to call the DoSomething method: Method 'App.DoSomething' not found.
// Unable to access the AField field: Field 'App.AField' not found.
// Unable to access the AnotherField field: Field 'App.AnotherField' not found.

상속 계층 구조

System.Object
   System.Exception
     System.SystemException
       System.MemberAccessException
        System.MissingMemberException
           System.MissingFieldException
           System.MissingMethodException

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 지원

참고 항목

참조

MissingMemberException 멤버
System 네임스페이스
Exception 클래스
MissingFieldException 클래스
MissingMethodException

기타 리소스

예외 처리 및 Throw