MissingFieldException MissingFieldException MissingFieldException MissingFieldException Class

Definice

Výjimka, která je vyvolána, když dojde k pokusu o dynamický přístup k poli, které neexistuje.The exception that is thrown when there is an attempt to dynamically access a field that does not exist. Pokud bylo pole v knihovně tříd odstraněno nebo přejmenováno, znovu zkompilujte všechna sestavení, která odkazují na tuto knihovnu.If a field in a class library has been removed or renamed, recompile any assemblies that reference that library.

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

Příklady

Tento příklad ukazuje, co se stane, když se pokusíte použít reflexi pro volání metody, která neexistuje, a přístup k poli, které neexistuje.This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. Aplikace se obnoví pomocí zachycení MissingMethodException, MissingFieldException, a MissingMemberException.The application recovers by catching the MissingMethodException, MissingFieldException, and 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.
Imports System
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

Při pokusu o přístup k neexistujícímu členu třídy se obvykle generuje chyba kompilace.Normally a compilation error is generated if code attempts to access a nonexistent member of a class. MissingFieldExceptionje navržena pro zpracování případů, kde se provede pokus dynamicky přistupovat k přejmenovanému nebo odstraněnému poli sestavení, na které není odkazováno pomocí silného názvu.MissingFieldException is designed to handle cases where an attempt is made to dynamically access a renamed or deleted field of an assembly that is not referenced by its strong name. Je MissingFieldException vyvolána, když se kód v závislém sestavení pokusí získat přístup k chybějícímu poli v sestavení, které bylo upraveno.The MissingFieldException is thrown when code in a dependent assembly attempts to access a missing field in an assembly that was modified.

MissingFieldExceptionpoužívá HRESULT COR_E_MISSINGFIELD, který má hodnotu 0x80131511.MissingFieldException uses the HRESULT COR_E_MISSINGFIELD, that has the value 0x80131511.

Seznam počáteční hodnoty vlastností pro instanci MissingFieldException, najdete v článku MissingFieldException konstruktory.For a list of initial property values for an instance of MissingFieldException, see the MissingFieldException constructors.

Konstruktory

MissingFieldException() MissingFieldException() MissingFieldException() MissingFieldException()

Inicializuje novou instanci třídy MissingFieldException třídy.Initializes a new instance of the MissingFieldException class.

MissingFieldException(SerializationInfo, StreamingContext) MissingFieldException(SerializationInfo, StreamingContext) MissingFieldException(SerializationInfo, StreamingContext) MissingFieldException(SerializationInfo, StreamingContext)

Inicializuje novou instanci třídy MissingFieldException třídy se serializovanými daty.Initializes a new instance of the MissingFieldException class with serialized data.

MissingFieldException(String) MissingFieldException(String) MissingFieldException(String) MissingFieldException(String)

Inicializuje novou instanci třídy MissingFieldException třídy pomocí zadané chybové zprávy.Initializes a new instance of the MissingFieldException class with a specified error message.

MissingFieldException(String, Exception) MissingFieldException(String, Exception) MissingFieldException(String, Exception) MissingFieldException(String, Exception)

Inicializuje novou instanci třídy MissingFieldException třídy pomocí zadané chybové zprávy a odkazu na vnitřní výjimku, která je příčinou této výjimky.Initializes a new instance of the MissingFieldException class with a specified error message and a reference to the inner exception that is the cause of this exception.

MissingFieldException(String, String) MissingFieldException(String, String) MissingFieldException(String, String) MissingFieldException(String, String)

Inicializuje novou instanci MissingFieldException třídy se zadaným názvem třídy a názvem pole.Initializes a new instance of the MissingFieldException class with the specified class name and field name.

Vlastnosti

Data Data Data Data

Získá kolekci párů klíč/hodnota, které poskytují další uživatelsky definované informace o výjimce.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

Získá nebo nastaví odkaz na soubor s nápovědě spojený s touto výjimkou.Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

Získá nebo nastaví hodnotu HRESULT, kódované číselné hodnoty, která je přiřazena konkrétní výjimce.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

Exception Získá instanci, která způsobila aktuální výjimku.Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

Získá textový řetězec zobrazující podpis chybějícího pole, název třídy a název pole.Gets the text string showing the signature of the missing field, the class name, and the field name. Tato vlastnost je pouze pro čtení.This property is read-only.

Source Source Source Source

Získá nebo nastaví název aplikace nebo objektu, který způsobuje chybu.Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

Načte řetězcovou reprezentaci okamžitých snímků v zásobníku volání.Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

Získá metodu, která vyvolá aktuální výjimku.Gets the method that throws the current exception.

(Inherited from Exception)

Metody

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Určuje, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

Při přepsání v odvozené třídě vrátí hodnotu Exception , která je hlavní příčinou jedné nebo více následných výjimek.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Slouží jako výchozí funkce hash.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo Nastaví objekt s názvem třídy, názvem člena, podpisem chybějícího členu a dalšími informacemi o výjimce.Sets the SerializationInfo object with the class name, the member name, the signature of the missing member, and additional exception information.

(Inherited from MissingMemberException)
GetType() GetType() GetType() GetType()

Získá typ modulu runtime aktuální instance.Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Vytvoří Mělkou kopii aktuální Object.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Vytvoří a vrátí řetězcovou reprezentaci aktuální výjimky.Creates and returns a string representation of the current exception.

(Inherited from Exception)

Události

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

Nastane, pokud je serializovaná výjimka pro vytvoření objektu stavu výjimky, který obsahuje Serializovaná data o výjimce.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Pole

ClassName ClassName ClassName ClassName

Obsahuje název třídy chybějícího člena.Holds the class name of the missing member.

(Inherited from MissingMemberException)
MemberName MemberName MemberName MemberName

Obsahuje název chybějícího člena.Holds the name of the missing member.

(Inherited from MissingMemberException)
Signature Signature Signature Signature

Obsahuje podpis chybějícího člena.Holds the signature of the missing member.

(Inherited from MissingMemberException)

Platí pro

Viz také