MissingFieldException Třída

Definice

Výjimka, která se vyvolá, když se pokusíte dynamicky získat přístup k poli, které neexistuje. Pokud bylo pole v knihovně tříd odebráno nebo přejmenováno, překompilujte všechna sestavení, která odkazují na tuto knihovnu.

public ref class MissingFieldException : MissingMemberException
public class MissingFieldException : MissingMemberException
[System.Serializable]
public class MissingFieldException : MissingMemberException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class MissingFieldException : MissingMemberException
type MissingFieldException = class
    inherit MissingMemberException
type MissingFieldException = class
    inherit MissingMemberException
    interface ISerializable
[<System.Serializable>]
type MissingFieldException = class
    inherit MissingMemberException
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MissingFieldException = class
    inherit MissingMemberException
    interface ISerializable
Public Class MissingFieldException
Inherits MissingMemberException
Dědičnost
Dědičnost
Atributy
Implementuje

Příklady

Tento příklad ukazuje, co se stane, když se pokusíte použít reflexi k volání metody, která neexistuje, a přístup k poli, které neexistuje. Aplikace se obnoví zachycením MissingMethodException, MissingFieldExceptiona MissingMemberException.

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.

Poznámky

Obvykle se vygeneruje chyba kompilace, pokud se kód pokusí o přístup k neexistující člen třídy. MissingFieldException je navržený tak, aby zpracovával případy, kdy je proveden pokus o dynamický přístup k přejmenovanému nebo odstraněným polím sestavení, na které není odkazováno silným názvem. Vyvolá se MissingFieldException , když se kód v závislém sestavení pokusí o přístup k chybějícímu poli v sestavení, které bylo změněno.

MissingFieldException používá COR_E_MISSINGFIELD HRESULT s hodnotou 0x80131511.

Seznam počátečních hodnot vlastností pro instanci MissingFieldExceptionnaleznete v MissingFieldException konstruktorech.

Konstruktory

MissingFieldException()

Inicializuje novou instanci MissingFieldException třídy.

MissingFieldException(SerializationInfo, StreamingContext)

Inicializuje novou instanci třídy MissingFieldException se serializovanými daty.

MissingFieldException(String)

Inicializuje novou instanci MissingFieldException třídy se zadanou chybovou zprávou.

MissingFieldException(String, Exception)

Inicializuje novou instanci MissingFieldException třídy se zadanou chybovou zprávou a odkazem na vnitřní výjimku, která je příčinou této výjimky.

MissingFieldException(String, String)

Inicializuje novou instanci MissingFieldException třídy se zadaným názvem třídy a názvem pole.

Pole

ClassName

Obsahuje název třídy chybějícího člena.

(Zděděno od MissingMemberException)
MemberName

Obsahuje název chybějícího člena.

(Zděděno od MissingMemberException)
Signature

Obsahuje podpis chybějícího člena.

(Zděděno od MissingMemberException)

Vlastnosti

Data

Získá kolekci párů klíč/hodnota, které poskytují další uživatelem definované informace o výjimce.

(Zděděno od Exception)
HelpLink

Získá nebo nastaví odkaz na soubor nápovědy přidružený k této výjimce.

(Zděděno od Exception)
HResult

Získá nebo nastaví HRESULT, kódovanou číselnou hodnotu přiřazenou konkrétní výjimce.

(Zděděno od Exception)
InnerException

Exception Získá instanci, která způsobila aktuální výjimku.

(Zděděno od Exception)
Message

Získá textový řetězec zobrazující podpis chybějícího pole, název třídy a název pole. Tato vlastnost je jen ke čtení.

Source

Získá nebo nastaví název aplikace nebo objektu, který způsobuje chybu.

(Zděděno od Exception)
StackTrace

Získá řetězcové znázornění okamžitých rámců v zásobníku volání.

(Zděděno od Exception)
TargetSite

Získá metodu, která vyvolá aktuální výjimku.

(Zděděno od Exception)

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetBaseException()

Při přepsání v odvozené třídě vrátí Exception hodnotu, která je hlavní příčinou jedné nebo více následných výjimek.

(Zděděno od Exception)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo Nastaví objekt názvem třídy, názvem člena, podpisem chybějícího člena a dalšími informacemi o výjimce.

(Zděděno od MissingMemberException)
GetType()

Získá typ modulu runtime aktuální instance.

(Zděděno od Exception)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vytvoří a vrátí řetězcovou reprezentaci aktuální výjimky.

(Zděděno od Exception)

událost

SerializeObjectState
Zastaralé.

Nastane, když je výjimka serializována k vytvoření objektu stavu výjimky, který obsahuje serializovaná data o výjimce.

(Zděděno od Exception)

Platí pro

Viz také