MissingMemberException Klas

Definitie

De uitzondering die wordt gegenereerd wanneer er een poging is om dynamisch toegang te krijgen tot een klasselid dat niet bestaat of die niet als openbaar wordt gedeclareerd. Als een lid 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 MissingMemberException : MemberAccessException
public class MissingMemberException : MemberAccessException
[System.Serializable]
public class MissingMemberException : MemberAccessException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class MissingMemberException : MemberAccessException
type MissingMemberException = class
    inherit MemberAccessException
type MissingMemberException = class
    inherit MemberAccessException
    interface ISerializable
[<System.Serializable>]
type MissingMemberException = class
    inherit MemberAccessException
    interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MissingMemberException = class
    inherit MemberAccessException
    interface ISerializable
Public Class MissingMemberException
Inherits MemberAccessException
Overname
MissingMemberException
Overname
Afgeleid
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 de code probeert toegang te krijgen tot een niet-bestaand lid van een klasse. MissingMemberException is ontworpen voor het afhandelen van gevallen waarin een veld of methode in één assembly wordt verwijderd of hernoemd en de wijziging niet wordt weerspiegeld in een tweede assembly. Tijdens runtime MissingMemberException wordt de code in de tweede assembly gegenereerd om toegang te krijgen tot het ontbrekende lid in de eerste assembly.

MissingMemberException is de basisklasse voor MissingFieldException en MissingMethodException. Over het algemeen is het beter om een van de afgeleide klassen MissingMemberException te gebruiken om nauwkeuriger de exacte aard van de fout aan te geven. Gooi een als MissingMemberException u alleen geïnteresseerd bent in het vastleggen van de algemene case van een ontbrekende lidfout.

MissingMemberException maakt gebruik van de HRESULT-COR_E_MISSINGMEMBER met de waarde 0x80131512.

Voor een lijst van initiële eigenschapswaarden voor een exemplaar van MissingMemberException, zie de MissingMemberException-constructoren.

Constructors

Name Description
MissingMemberException()

Initialiseert een nieuw exemplaar van de MissingMemberException klasse.

MissingMemberException(SerializationInfo, StreamingContext)
Verouderd.

Initialiseert een nieuw exemplaar van de MissingMemberException klasse met geserialiseerde gegevens.

MissingMemberException(String, Exception)

Initialiseert een nieuw exemplaar van de MissingMemberException klasse met een opgegeven foutbericht en een verwijzing naar de binnenste uitzondering die de hoofdoorzaak van deze uitzondering is.

MissingMemberException(String, String)

Initialiseert een nieuw exemplaar van de MissingMemberException klasse met de opgegeven klassenaam en lidnaam.

MissingMemberException(String)

Initialiseert een nieuw exemplaar van de MissingMemberException klasse met een opgegeven foutbericht.

Velden

Name Description
ClassName

Bevat de klassenaam van het ontbrekende lid.

MemberName

Bevat de naam van het ontbrekende lid.

Signature

Bevat de handtekening van het ontbrekende lid.

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 klassenaam, de naam van het lid en de handtekening van het ontbrekende lid.

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)
Verouderd.

Hiermee stelt u het SerializationInfo object in met de klassenaam, de lidnaam, de handtekening van het ontbrekende lid en aanvullende uitzonderingsgegevens.

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
Verouderd.

Treedt op wanneer een uitzondering wordt geserialiseerd om een uitzonderingsstatusobject te maken dat geserialiseerde gegevens over de uitzondering bevat.

(Overgenomen van Exception)

Van toepassing op

Zie ook