MissingFieldException Klas
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
De uitzondering die wordt gegenereerd wanneer er een poging is om dynamisch toegang te krijgen tot een veld dat niet bestaat. Als een veld in een klassebibliotheek is verwijderd of een andere naam heeft gekregen, moet u alle assembly's die naar die bibliotheek verwijzen, opnieuw compileren.
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
[<System.Serializable>]
type MissingFieldException = class
inherit MissingMemberException
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MissingFieldException = class
inherit MissingMemberException
interface ISerializable
type MissingFieldException = class
inherit MissingMemberException
interface ISerializable
Public Class MissingFieldException
Inherits MissingMemberException
- Overname
- Overname
- Kenmerken
- Implementeringen
Voorbeelden
In dit voorbeeld ziet u wat er gebeurt als u reflectie probeert te gebruiken om een methode aan te roepen die niet bestaat en toegang krijgt tot een veld dat niet bestaat. De toepassing herstelt door de MissingMethodException, MissingFieldExceptionen 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.
Opmerkingen
Normaal gesproken wordt er een compilatiefout gegenereerd als code probeert toegang te krijgen tot een niet-bestaand lid van een klasse. MissingFieldException is ontworpen voor het afhandelen van gevallen waarin een poging wordt gedaan om dynamisch toegang te krijgen tot een hernoemd of verwijderd veld van een assembly waarnaar niet wordt verwezen door de sterke naam. De MissingFieldException fout wordt gegenereerd wanneer code in een afhankelijke assembly probeert toegang te krijgen tot een ontbrekend veld in een assembly die is gewijzigd.
MissingFieldException maakt gebruik van de HRESULT-COR_E_MISSINGFIELD, met de waarde 0x80131511.
Voor een lijst van initiƫle eigenschapswaarden voor een exemplaar van MissingFieldException, zie de MissingFieldException-constructoren.
Constructors
| Name | Description |
|---|---|
| MissingFieldException() |
Initialiseert een nieuw exemplaar van de MissingFieldException klasse. |
| MissingFieldException(SerializationInfo, StreamingContext) |
Initialiseert een nieuw exemplaar van de MissingFieldException klasse met geserialiseerde gegevens. |
| MissingFieldException(String, Exception) |
Initialiseert een nieuw exemplaar van de MissingFieldException klasse met een opgegeven foutbericht en een verwijzing naar de binnenste uitzondering die de oorzaak van deze uitzondering is. |
| MissingFieldException(String, String) |
Initialiseert een nieuw exemplaar van de MissingFieldException klasse met de opgegeven klassenaam en veldnaam. |
| MissingFieldException(String) |
Initialiseert een nieuw exemplaar van de MissingFieldException klasse met een opgegeven foutbericht. |
Velden
| Name | Description |
|---|---|
| ClassName |
Bevat de klassenaam van het ontbrekende lid. (Overgenomen van MissingMemberException) |
| MemberName |
Bevat de naam van het ontbrekende lid. (Overgenomen van MissingMemberException) |
| Signature |
Bevat de handtekening van het ontbrekende lid. (Overgenomen van MissingMemberException) |
Eigenschappen
| Name | Description |
|---|---|
| Data |
Hiermee haalt u een verzameling sleutel-waardeparen op die aanvullende door de gebruiker gedefinieerde informatie over de uitzondering bieden. (Overgenomen van Exception) |
| HelpLink |
Hiermee haalt u een koppeling op naar het Help-bestand dat aan deze uitzondering is gekoppeld. (Overgenomen van Exception) |
| HResult |
Hiermee wordt HRESULT opgehaald of ingesteld, een gecodeerde numerieke waarde die is toegewezen aan een specifieke uitzondering. (Overgenomen van Exception) |
| InnerException |
Hiermee haalt u het Exception exemplaar op dat de huidige uitzondering heeft veroorzaakt. (Overgenomen van Exception) |
| Message |
Hiermee haalt u de tekenreeks op met de handtekening van het ontbrekende veld, de klassenaam en de veldnaam. Deze eigenschap is alleen-lezen. |
| Source |
Hiermee wordt de naam van de toepassing of het object dat de fout veroorzaakt, opgehaald of ingesteld. (Overgenomen van Exception) |
| StackTrace |
Hiermee haalt u een tekenreeksweergave van de directe frames op de aanroepstack op. (Overgenomen van Exception) |
| TargetSite |
Hiermee haalt u de methode op waarmee de huidige uitzondering wordt gegenereerd. (Overgenomen van Exception) |
Methoden
| Name | Description |
|---|---|
| Equals(Object) |
Bepaalt of het opgegeven object gelijk is aan het huidige object. (Overgenomen van Object) |
| GetBaseException() |
Wanneer deze wordt overschreven in een afgeleide klasse, retourneert u de Exception hoofdoorzaak van een of meer volgende uitzonderingen. (Overgenomen van Exception) |
| GetHashCode() |
Fungeert als de standaardhashfunctie. (Overgenomen van Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Hiermee stelt u het SerializationInfo object in met de klassenaam, de lidnaam, de handtekening van het ontbrekende lid en aanvullende uitzonderingsgegevens. (Overgenomen van MissingMemberException) |
| GetType() |
Hiermee haalt u het runtimetype van het huidige exemplaar op. (Overgenomen van Exception) |
| MemberwiseClone() |
Hiermee maakt u een ondiepe kopie van de huidige Object. (Overgenomen van Object) |
| ToString() |
Hiermee maakt en retourneert u een tekenreeksweergave van de huidige uitzondering. (Overgenomen van Exception) |
gebeurtenis
| Name | Description |
|---|---|
| SerializeObjectState |
Treedt op wanneer een uitzondering wordt geserialiseerd om een uitzonderingsstatusobject te maken dat geserialiseerde gegevens over de uitzondering bevat. (Overgenomen van Exception) |