MissingFieldException MissingFieldException MissingFieldException MissingFieldException Class

Definizione

Eccezione generata quando si verifica un tentativo di accesso dinamico a un campo non esistente.The exception that is thrown when there is an attempt to dynamically access a field that does not exist. Se un campo di una libreria di classi è stato rimosso, ricompilare ogni assembly che fa riferimento alla libreria.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
Ereditarietà
Attributi
Implementazioni

Esempi

Questo esempio viene illustrato cosa accade se si prova a usare la reflection per chiamare un metodo che non esiste e l'accesso a un campo che non esiste.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. L'applicazione venga ripristinata rilevando i MissingMethodException, MissingFieldException, e 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.

Commenti

In genere viene generato un errore di compilazione se il codice tenta di accedere a un membro inesistente di una classe.Normally a compilation error is generated if code attempts to access a nonexistent member of a class. MissingFieldException è progettato per gestire i casi in cui viene effettuato un tentativo di accesso dinamico a un campo eliminato o rinominato di un assembly che non fa riferimento il nome sicuro.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. Il MissingFieldException viene generata quando il codice in un assembly dipendente tenta di accedere a un campo mancano in un assembly a cui è stato modificato.The MissingFieldException is thrown when code in a dependent assembly attempts to access a missing field in an assembly that was modified.

MissingFieldException utilizza COR_E_MISSINGFIELD HRESULT, che ha il valore 0x80131511.MissingFieldException uses the HRESULT COR_E_MISSINGFIELD, that has the value 0x80131511.

Per un elenco di valori di proprietà iniziali per un'istanza di MissingFieldException, vedere il MissingFieldException costruttori.For a list of initial property values for an instance of MissingFieldException, see the MissingFieldException constructors.

Costruttori

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

Inizializza una nuova istanza della classe MissingFieldException.Initializes a new instance of the MissingFieldException class.

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

Inizializza una nuova istanza della classe MissingFieldException con dati serializzati.Initializes a new instance of the MissingFieldException class with serialized data.

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

Inizializza una nuova istanza della classe MissingFieldException con un messaggio di errore specificato.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)

Inizializza una nuova istanza della classe MissingFieldException con un messaggio di errore specificato e un riferimento all'eccezione interna che è la causa dell'eccezione corrente.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)

Inizializza una nuova istanza della classe MissingFieldException con il nome di campo e il nome di classe specificati.Initializes a new instance of the MissingFieldException class with the specified class name and field name.

Proprietà

Data Data Data Data

Ottiene una raccolta di coppie chiave-valore che fornisce informazioni aggiuntive definite dall'utente relative all'eccezione.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

Ottiene o imposta un collegamento al file della Guida associato all'eccezione.Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

Ottiene o imposta HRESULT, un valore numerico codificato che viene assegnato a un'eccezione specifica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

Ottiene l'istanza di Exception che ha causato l'eccezione corrente.Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

Recupera la stringa che mostra la firma del campo mancante, il nome della classe e il nome del campo.Gets the text string showing the signature of the missing field, the class name, and the field name. Questa proprietà è di sola lettura.This property is read-only.

Source Source Source Source

Ottiene o imposta il nome dell'oggetto o dell'applicazione che ha generato l'errore.Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

Ottiene una rappresentazione di stringa dei frame immediati nello stack di chiamate.Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

Ottiene il metodo che genera l'eccezione corrente.Gets the method that throws the current exception.

(Inherited from Exception)

Metodi

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

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

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

Se utilizzato come metodo di override in una classe derivata, restituisce l'Exception che è la causa radice di una o più eccezioni successive.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()

Funge da funzione hash predefinita.Serves as the default hash function.

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

Imposta l'oggetto SerializationInfo con il nome della classe, il nome del membro, la firma del membro mancante e informazioni aggiuntive sull'eccezione.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()

Ottiene il tipo di runtime dell'istanza corrente.Gets the runtime type of the current instance.

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

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

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

Crea e restituisce una rappresentazione di stringa dell'eccezione corrente.Creates and returns a string representation of the current exception.

(Inherited from Exception)

Eventi

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

Si verifica quando un'eccezione viene serializzata per creare un oggetto di stato eccezione contenente i dati serializzati relativi all'eccezione.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Campi

ClassName ClassName ClassName ClassName

Contiene il nome della classe del membro mancante.Holds the class name of the missing member.

(Inherited from MissingMemberException)
MemberName MemberName MemberName MemberName

Contiene il nome del membro mancante.Holds the name of the missing member.

(Inherited from MissingMemberException)
Signature Signature Signature Signature

Contiene la firma del membro mancante.Holds the signature of the missing member.

(Inherited from MissingMemberException)

Si applica a

Vedi anche