MissingFieldException Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Excepción que se produce cuando hay un intento de acceder dinámicamente a un campo que no existe. Si se ha quitado o cambiado el nombre de un campo de una biblioteca de clases, vuelva a compilar los ensamblados que hacen referencia a esa biblioteca.
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
- Herencia
- Herencia
- Atributos
- Implementaciones
Ejemplos
En este ejemplo se muestra lo que sucede si intenta usar la reflexión para llamar a un método que no existe y acceder a un campo que no existe. La aplicación se recupera detectando el MissingMethodException, MissingFieldExceptiony 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.
Comentarios
Normalmente, se genera un error de compilación si el código intenta acceder a un miembro inexistente de una clase. MissingFieldException está diseñado para controlar los casos en los que se intenta acceder dinámicamente a un campo cambiado o eliminado de un ensamblado al que no hace referencia su nombre seguro. MissingFieldException se produce cuando el código de un ensamblado dependiente intenta tener acceso a un campo que falta en un ensamblado que se modificó.
MissingFieldException usa el COR_E_MISSINGFIELD HRESULT, que tiene el valor 0x80131511.
Para obtener una lista de valores de propiedad iniciales para una instancia de MissingFieldException, vea los MissingFieldException constructores.
Constructores
| Nombre | Description |
|---|---|
| MissingFieldException() |
Inicializa una nueva instancia de la clase MissingFieldException. |
| MissingFieldException(SerializationInfo, StreamingContext) |
Obsoletos.
Inicializa una nueva instancia de la MissingFieldException clase con datos serializados. |
| MissingFieldException(String, Exception) |
Inicializa una nueva instancia de la MissingFieldException clase con un mensaje de error especificado y una referencia a la excepción interna que es la causa de esta excepción. |
| MissingFieldException(String, String) |
Inicializa una nueva instancia de la MissingFieldException clase con el nombre de clase y el nombre de campo especificados. |
| MissingFieldException(String) |
Inicializa una nueva instancia de la MissingFieldException clase con un mensaje de error especificado. |
Campos
| Nombre | Description |
|---|---|
| ClassName |
Contiene el nombre de clase del miembro que falta. (Heredado de MissingMemberException) |
| MemberName |
Contiene el nombre del miembro que falta. (Heredado de MissingMemberException) |
| Signature |
Contiene la firma del miembro que falta. (Heredado de MissingMemberException) |
Propiedades
| Nombre | Description |
|---|---|
| Data |
Obtiene una colección de pares clave-valor que proporcionan información adicional definida por el usuario sobre la excepción. (Heredado de Exception) |
| HelpLink |
Obtiene o establece un vínculo al archivo de ayuda asociado a esta excepción. (Heredado de Exception) |
| HResult |
Obtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica. (Heredado de Exception) |
| InnerException |
Obtiene la Exception instancia que provocó la excepción actual. (Heredado de Exception) |
| Message |
Obtiene la cadena de texto que muestra la firma del campo que falta, el nombre de clase y el nombre del campo. Esta propiedad es de solo lectura. |
| Source |
Obtiene o establece el nombre de la aplicación o el objeto que provoca el error. (Heredado de Exception) |
| StackTrace |
Obtiene una representación de cadena de los fotogramas inmediatos en la pila de llamadas. (Heredado de Exception) |
| TargetSite |
Obtiene el método que produce la excepción actual. (Heredado de Exception) |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetBaseException() |
Cuando se reemplaza en una clase derivada, devuelve la Exception causa principal de una o varias excepciones posteriores. (Heredado de Exception) |
| GetHashCode() |
Actúa como función hash predeterminada. (Heredado de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Obsoletos.
Establece el objeto SerializationInfo con el nombre de clase, el nombre del miembro, la firma del miembro que falta y la información de excepción adicional. (Heredado de MissingMemberException) |
| GetType() |
Obtiene el tipo de tiempo de ejecución de la instancia actual. (Heredado de Exception) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Crea y devuelve una representación de cadena de la excepción actual. (Heredado de Exception) |
Eventos
| Nombre | Description |
|---|---|
| SerializeObjectState |
Obsoletos.
Se produce cuando se serializa una excepción para crear un objeto de estado de excepción que contiene datos serializados sobre la excepción. (Heredado de Exception) |