다음을 통해 공유


MissingMethodException 클래스

존재하지 않는 메서드를 동적으로 액세스하려고 할 때 throw되는 예외입니다.

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

구문

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

설명

코드에서 존재하지 않는 클래스 메서드에 액세스하려고 하면 일반적으로 컴파일 오류가 발생합니다. MissingMethodException은 강력한 이름으로 참조되지 않는 어셈블리의 메서드 중 이름이 바뀌었거나 삭제된 메서드에 동적으로 액세스하려는 경우를 처리하기 위한 것입니다. 종속 어셈블리의 코드에서 수정된 어셈블리에 없는 메서드에 액세스하면 MissingMethodException이 throw됩니다.

MissingMethodException은 0x80131513 값을 가지는 HRESULT COR_E_MISSINGMETHOD를 사용합니다.

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

예제

이 예제에서는 리플렉션을 사용하여 존재하지 않는 메서드를 호출하고 존재하지 않는 필드에 액세스하려고 하는 경우 어떠한 일이 발생하는지 보여 줍니다. 응용 프로그램은 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.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에서 지원

참고 항목

참조

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

기타 리소스

예외 처리 및 Throw