MissingMemberException Klasse

Definition

Die Ausnahme, die beim Versuch ausgelöst wird, dynamisch auf einen Klassenmember zuzugreifen, der nicht vorhanden oder nicht als öffentlich deklariert ist. Wenn ein Member in einer Klassenbibliothek entfernt oder umbenannt wurde, kompilieren Sie alle Assemblys erneut, die diese Bibliothek verwenden.

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

Beispiele

In diesem Beispiel wird gezeigt, was geschieht, wenn Sie versuchen, eine nicht vorhandene Methode mithilfe von Reflektion aufzurufen und auf ein Feld zuzugreifen, das nicht vorhanden ist. Die Anwendung wird wiederhergestellt, indem sie , MissingMethodExceptionMissingFieldExceptionund MissingMemberExceptionabfangen.

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 method,
        // a MissingMethodException 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.
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 der Code versucht, auf einen nicht vorhandenen Member einer Klasse zuzugreifen. MissingMemberException ist für Fälle konzipiert, in denen ein Feld oder eine Methode in einer Assembly gelöscht oder umbenannt wird und die Änderung nicht in einer zweiten Assembly widerzuspiegeln ist. Zur Laufzeit wird ausgelöst, wenn der Code in der zweiten Assembly versucht, MissingMemberException auf den fehlenden Member in der ersten Assembly zuzugreifen.

MissingMemberException ist die Basisklasse für MissingFieldException und MissingMethodException. Im Allgemeinen ist es besser, eine der abgeleiteten Klassen von MissingMemberException zu verwenden, um die genaue Art des Fehlers genauer anzugeben. Lösen Sie aus MissingMemberException , wenn Sie nur den allgemeinen Fall eines fehlenden Memberfehlers erfassen möchten.

MissingMemberException verwendet die HRESULT-COR_E_MISSINGMEMBER, die den Wert 0x80131512 hat.

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

Konstruktoren

MissingMemberException()

Initialisiert eine neue Instanz der MissingMemberException-Klasse.

MissingMemberException(SerializationInfo, StreamingContext)

Initialisiert eine neue Instanz der MissingMemberException-Klasse mit serialisierten Daten.

MissingMemberException(String)

Initialisiert eine neue Instanz der MissingMemberException-Klasse mit einer angegebenen Fehlermeldung.

MissingMemberException(String, Exception)

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

MissingMemberException(String, String)

Initialisiert eine neue Instanz der MissingMemberException-Klasse unter Verwendung des angegebenen Klassen- und Membernamens.

Felder

ClassName

Enthält den Klassennamen des fehlenden Members.

MemberName

Enthält den Namen des fehlenden Members.

Signature

Enthält die Signatur des fehlenden Members.

Eigenschaften

Data

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

(Geerbt von Exception)
HelpLink

Ruft einen Link zur Hilfedatei ab, die dieser Ausnahme zugeordnet ist, oder legt einen Link fest.

(Geerbt von Exception)
HResult

Ruft HRESULT ab oder legt HRESULT fest. Dies ist ein codierter Wert, der einer bestimmten Ausnahme zugeordnet 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, Membernamen und der Signatur des fehlenden Members ab.

Source

Gibt den Namen der Anwendung oder des Objekts zurück, die bzw. das den Fehler verursacht hat, oder legt diesen fest.

(Geerbt von Exception)
StackTrace

Ruft eine Zeichenfolgendarstellung der unmittelbaren Frames in der Aufrufliste ab.

(Geerbt von Exception)
TargetSite

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

(Geerbt von Exception)

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetBaseException()

Gibt beim Überschreiben in einer abgeleiteten Klasse eine Exception zurück, die die Grundursache für eine oder mehrere nachfolgende Ausnahmen ist.

(Geerbt von Exception)
GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetObjectData(SerializationInfo, StreamingContext)

Legt das SerializationInfo-Objekt mit dem Klassennamen, dem Membernamen, der Signatur des fehlenden Members sowie zusätzlichen Ausnahmeinformationen fest.

GetObjectData(SerializationInfo, StreamingContext)

Legt beim Überschreiben in einer abgeleiteten Klasse die SerializationInfo mit Informationen über die Ausnahme fest.

(Geerbt von Exception)
GetType()

Ruft den Laufzeittyp der aktuellen Instanz ab.

(Geerbt von Exception)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

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

(Geerbt von Exception)

Ereignisse

SerializeObjectState
Veraltet.

Tritt auf, wenn eine Ausnahme serialisiert wird, um ein Ausnahmezustandsobjekt mit serialisierten Daten über die Ausnahme zu erstellen.

(Geerbt von Exception)

Gilt für:

Weitere Informationen