MissingMemberException Osztály

Definíció

Az a kivétel, amely akkor jelenik meg, ha egy nem létező vagy nem nyilvánosként deklarált osztálytaghoz próbál dinamikusan hozzáférni. Ha egy osztálytár egyik tagját eltávolították vagy átnevezték, az adott kódtárra hivatkozó szerelvényeket újrafordítsuk.

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
Öröklődés
MissingMemberException
Öröklődés
Származtatott
Attribútumok
Megvalósítás

Példák

Ez a példa bemutatja, mi történik, ha a tükröződés használatával próbál meghívni egy nem létező metódust, és egy nem létező mezőhöz fér hozzá. Az alkalmazás a , MissingMethodExceptionés MissingFieldExceptiona 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.

Megjegyzések

Általában fordítási hiba jön létre, ha a kód egy osztály nem létező tagját próbálja elérni. MissingMemberException olyan esetek kezelésére szolgál, amikor egy mezőt vagy metódust törölnek vagy átneveznek egy szerelvényben, és a módosítás nem jelenik meg a második szerelvényben. Futásidőben a rendszer akkor küldi el a kódot, MissingMemberException amikor a második szerelvény kódja megpróbálja elérni a hiányzó tagot az első szerelvényben.

MissingMemberException az alaposztálya a MissingFieldException és MissingMethodException osztályoknak. Általában jobb az egyik származtatott osztályt MissingMemberException használni, hogy pontosabban jelezze a hiba pontos jellegét. MissingMemberException Ha csak a hiányzó taghibák általános esetét szeretné rögzíteni, adjon meg egy elemet.

MissingMemberException A HRESULT COR_E_MISSINGMEMBER használja, amelynek értéke 0x80131512.

A MissingMemberException példány kezdeti tulajdonságainak listájáért tekintse meg a MissingMemberException konstruktorokat.

Konstruktorok

Name Description
MissingMemberException()

Inicializálja a MissingMemberException osztály új példányát.

MissingMemberException(SerializationInfo, StreamingContext)
Elavult.

Inicializálja az MissingMemberException osztály új példányát szerializált adatokkal.

MissingMemberException(String, Exception)

Inicializálja az MissingMemberException osztály egy új példányát egy megadott hibaüzenettel és a kivétel kiváltó okaként szolgáló belső kivételre mutató hivatkozással.

MissingMemberException(String, String)

Inicializálja az MissingMemberException osztály új példányát a megadott osztálynévvel és tagnévvel.

MissingMemberException(String)

Inicializálja az MissingMemberException osztály új példányát egy megadott hibaüzenettel.

Mezők

Name Description
ClassName

A hiányzó tag osztálynevét tartalmazza.

MemberName

A hiányzó tag nevét tartalmazza.

Signature

A hiányzó tag aláírását tartalmazza.

Tulajdonságok

Name Description
Data

Lekéri a kulcs-/érték párok gyűjteményét, amelyek további, felhasználó által definiált információkat biztosítanak a kivételről.

(Öröklődés forrása Exception)
HelpLink

Lekéri vagy beállítja a kivételhez társított súgófájlra mutató hivatkozást.

(Öröklődés forrása Exception)
HResult

Lekéri vagy beállítja a HRESULT-ot, egy kódolt numerikus értéket, amely egy adott kivételhez van hozzárendelve.

(Öröklődés forrása Exception)
InnerException

Lekéri az Exception aktuális kivételt okozó példányt.

(Öröklődés forrása Exception)
Message

Lekéri a hiányzó tag osztálynevét, tagnevét és aláírását megjelenítő szöveges sztringet.

Source

Lekéri vagy beállítja az alkalmazás vagy a hibát okozó objektum nevét.

(Öröklődés forrása Exception)
StackTrace

Lekéri a hívásverem közvetlen kereteinek sztringképét.

(Öröklődés forrása Exception)
TargetSite

Lekéri az aktuális kivételt okozó metódust.

(Öröklődés forrása Exception)

Metódusok

Name Description
Equals(Object)

Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal.

(Öröklődés forrása Object)
GetBaseException()

Ha egy származtatott osztály felül van bírálva, egy Exception vagy több későbbi kivétel kiváltó okát adja vissza.

(Öröklődés forrása Exception)
GetHashCode()

Ez az alapértelmezett kivonatoló függvény.

(Öröklődés forrása Object)
GetObjectData(SerializationInfo, StreamingContext)
Elavult.

Beállítja az SerializationInfo objektumot az osztály nevével, a tag nevével, a hiányzó tag aláírásával és további kivételadatokkal.

GetType()

Lekéri az aktuális példány futtatókörnyezeti típusát.

(Öröklődés forrása Exception)
MemberwiseClone()

Az aktuális Objectpéldány sekély másolatát hozza létre.

(Öröklődés forrása Object)
ToString()

Létrehozza és visszaadja az aktuális kivétel sztring-ábrázolását.

(Öröklődés forrása Exception)

esemény

Name Description
SerializeObjectState
Elavult.

Akkor fordul elő, ha a kivétel szerializálva van egy kivételállapot-objektum létrehozásához, amely szerializált adatokat tartalmaz a kivételről.

(Öröklődés forrása Exception)

A következőre érvényes:

Lásd még