Freigeben über


MissingMethodException Klasse

Definition

Die Ausnahme, die ausgelöst wird, wenn versucht wird, dynamisch auf eine Methode zuzugreifen, die nicht vorhanden ist.

public ref class MissingMethodException : MissingMemberException
public class MissingMethodException : MissingMemberException
[System.Serializable]
public class MissingMethodException : MissingMemberException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class MissingMethodException : MissingMemberException
type MissingMethodException = class
    inherit MissingMemberException
type MissingMethodException = class
    inherit MissingMemberException
    interface ISerializable
[<System.Serializable>]
type MissingMethodException = class
    inherit MissingMemberException
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MissingMethodException = class
    inherit MissingMemberException
    interface ISerializable
Public Class MissingMethodException
Inherits MissingMemberException
Vererbung
Vererbung
Attribute
Implementiert

Beispiele

In diesem Beispiel wird gezeigt, was passiert, wenn Sie versuchen, eine Methode aufzurufen, die nicht vorhanden ist, und auf ein feld zugreifen, das nicht vorhanden ist. Die Anwendung wird wiederhergestellt, indem sie die MissingMethodException, MissingFieldExceptionund MissingMemberException.

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 method,
            // a MissingMethodException 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 example 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.
open System
open System.Reflection

type App = class end

try
    // Attempt to call a static DoSomething method defined in the App class.
    // However, because the App class does not define this method,
    // a MissingMethodException is thrown.
    typeof<App>.InvokeMember("DoSomething", BindingFlags.Static ||| BindingFlags.InvokeMethod, null, null, null)
    |> ignore
with :? MissingMethodException as e ->
    // Show the user that the DoSomething method cannot be called.
    printfn $"Unable to call the DoSomething method: {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, [| box 5 |])
    |> ignore
with :? MissingFieldException as e ->
    // Show the user that the AField field cannot be accessed.
    printfn $"Unable to access the AField field: {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)
    |> ignore
with :? MissingMemberException as 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.
    printfn $"Unable to access the AnotherField field: {e.Message}"
// This code example 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.
Imports System.Reflection

Public Class App
    Public Shared Sub Main() 
        Try
            ' Attempt to call a static DoSomething method defined in the App class.
            ' However, because the App class does not define this method, 
            ' a MissingMethodException is thrown.
            GetType(App).InvokeMember("DoSomething", BindingFlags.Static Or BindingFlags.InvokeMethod, _
                                       Nothing, Nothing, Nothing)
        Catch e As MissingMethodException
            ' Show the user that the DoSomething method cannot be called.
            Console.WriteLine("Unable to call the DoSomething method: {0}", e.Message)
        End Try
        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.
            GetType(App).InvokeMember("AField", BindingFlags.Static Or BindingFlags.SetField, _
                                       Nothing, Nothing, New [Object]() {5})
        Catch e As MissingFieldException
            ' Show the user that the AField field cannot be accessed.
            Console.WriteLine("Unable to access the AField field: {0}", e.Message)
        End Try
        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.
            GetType(App).InvokeMember("AnotherField", BindingFlags.Static Or BindingFlags.GetField, _
                                       Nothing, Nothing, Nothing)
        Catch e As MissingMemberException
            ' 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)
        End Try
    End Sub 
End Class 
' This code example 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.

Hinweise

Normalerweise wird ein Kompilierungsfehler generiert, wenn Code versucht, auf eine nicht vorhandene Methode einer Klasse zuzugreifen. MissingMethodException wurde entwickelt, um Fälle zu behandeln, in denen versucht wird, dynamisch auf eine umbenannte oder gelöschte Methode einer Assembly zuzugreifen, auf die nicht durch den starken Namen verwiesen wird. MissingMethodException wird ausgelöst, wenn Code in einer abhängigen Assembly versucht, auf eine fehlende Methode in einer Assembly zuzugreifen, die geändert wurde.

MissingMethodException verwendet die HRESULT-COR_E_MISSINGMETHOD mit dem Wert 0x80131513.

Eine Liste der anfänglichen Eigenschaftswerte für eine Instanz von MissingMethodException, finden Sie unter den MissingMethodException Konstruktoren.

Der genaue Zeitpunkt, zu dem statisch verwiesene Methoden geladen werden, ist nicht angegeben. Diese Ausnahme kann ausgelöst werden, bevor die Methode, die auf die fehlende Methode verweist, mit der Ausführung beginnt.

Konstruktoren

Name Beschreibung
MissingMethodException()

Initialisiert eine neue Instanz der MissingMethodException-Klasse.

MissingMethodException(SerializationInfo, StreamingContext)
Veraltet.

Initialisiert eine neue Instanz der MissingMethodException Klasse mit serialisierten Daten.

MissingMethodException(String, Exception)

Initialisiert eine neue Instanz der MissingMethodException Klasse mit einer angegebenen Fehlermeldung und einem Verweis auf die innere Ausnahme, die die Ursache dieser Ausnahme ist.

MissingMethodException(String, String)

Initialisiert eine neue Instanz der MissingMethodException Klasse mit dem angegebenen Klassennamen und Methodennamen.

MissingMethodException(String)

Initialisiert eine neue Instanz der MissingMethodException Klasse mit einer angegebenen Fehlermeldung.

Felder

Name Beschreibung
ClassName

Enthält den Klassennamen des fehlenden Elements.

(Geerbt von MissingMemberException)
MemberName

Enthält den Namen des fehlenden Elements.

(Geerbt von MissingMemberException)
Signature

Enthält die Signatur des fehlenden Elements.

(Geerbt von MissingMemberException)

Eigenschaften

Name Beschreibung
Data

Ruft eine Auflistung von Schlüssel-Wert-Paaren ab, die zusätzliche benutzerdefinierte Informationen zur Ausnahme bereitstellen.

(Geerbt von Exception)
HelpLink

Dient zum Abrufen oder Festlegen eines Links zur Hilfedatei, die dieser Ausnahme zugeordnet ist.

(Geerbt von Exception)
HResult

Dient zum Abrufen oder Festlegen von HRESULT, einem codierten numerischen Wert, der einer bestimmten Ausnahme zugewiesen ist.

(Geerbt von Exception)
InnerException

Ruft die Exception Instanz ab, die die aktuelle Ausnahme verursacht hat.

(Geerbt von Exception)
Message

Ruft die Textzeichenfolge mit dem Klassennamen, dem Methodennamen und der Signatur der fehlenden Methode ab. Diese Eigenschaft ist schreibgeschützt.

Source

Dient zum Abrufen oder Festlegen des Namens der Anwendung oder des Objekts, das den Fehler verursacht.

(Geerbt von Exception)
StackTrace

Ruft eine Zeichenfolgendarstellung der unmittelbaren Frames im Aufrufstapel ab.

(Geerbt von Exception)
TargetSite

Ruft die Methode ab, die die aktuelle Ausnahme auslöst.

(Geerbt von Exception)

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
GetBaseException()

Wenn sie in einer abgeleiteten Klasse überschrieben wird, wird die Exception Ursache einer oder mehrerer nachfolgenden Ausnahmen zurückgegeben.

(Geerbt von Exception)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetObjectData(SerializationInfo, StreamingContext)
Veraltet.

Legt das SerializationInfo Objekt mit dem Klassennamen, dem Membernamen, der Signatur des fehlenden Elements und zusätzliche Ausnahmeinformationen fest.

(Geerbt von MissingMemberException)
GetType()

Ruft den Laufzeittyp der aktuellen Instanz ab.

(Geerbt von Exception)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Erstellt und gibt eine Zeichenfolgendarstellung der aktuellen Ausnahme zurück.

(Geerbt von Exception)

Ereignisse

Name Beschreibung
SerializeObjectState
Veraltet.

Tritt auf, wenn eine Ausnahme serialisiert wird, um ein Ausnahmestatusobjekt zu erstellen, das serialisierte Daten zu der Ausnahme enthält.

(Geerbt von Exception)

Gilt für:

Weitere Informationen