MissingMemberException Sınıf

Tanım

Mevcut olmayan veya genel olarak bildirilmeyen bir sınıf üyesine dinamik olarak erişme girişimi olduğunda oluşan özel durum. Sınıf kitaplığındaki bir üye kaldırıldıysa veya yeniden adlandırıldıysa, bu kitaplığa başvuran derlemeleri yeniden derleyin.

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
Devralma
MissingMemberException
Devralma
Türetilmiş
Öznitelikler
Uygulamalar

Örnekler

Bu örnek, var olmayan bir yöntemi çağırmak ve var olmayan bir alana erişmek için yansıma kullanmayı denediğinizde ne olacağını gösterir. Uygulama , MissingFieldExceptionve MissingMemberExceptiondeğerlerini yakalayarak MissingMethodExceptionkurtarılır.

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

Açıklamalar

Normalde kod bir sınıfın var olmayan bir üyesine erişmeye çalışırsa derleme hatası oluşturulur. MissingMemberException , bir alanın veya yöntemin bir derlemede silindiği veya yeniden adlandırıldığı ve değişikliğin ikinci bir derlemeye yansıtılmadığı durumları işlemek için tasarlanmıştır. çalışma zamanında, MissingMemberException ikinci derlemedeki kod ilk derlemedeki eksik üyeye erişmeye çalıştığında oluşturulur.

MissingMemberExceptionve MissingMethodExceptioniçin MissingFieldException temel sınıftır. Genel olarak, hatanın tam doğasını daha kesin belirtmek için türetilmiş sınıflarından MissingMemberException birini kullanmak daha iyidir. MissingMemberException Yalnızca eksik üye hatasının genel durumunu yakalamak istiyorsanız bir at.

MissingMemberException değeri 0x80131512 olan HRESULT COR_E_MISSINGMEMBER kullanır.

örneğinin ilk özellik değerlerinin MissingMemberExceptionlistesi için oluşturuculara MissingMemberException bakın.

Oluşturucular

MissingMemberException()

MissingMemberException sınıfının yeni bir örneğini başlatır.

MissingMemberException(SerializationInfo, StreamingContext)

MissingMemberException sınıfının yeni bir örneğini serileştirilmiş verilerle başlatır.

MissingMemberException(String)

Belirtilen hata iletisiyle sınıfının yeni bir örneğini MissingMemberException başlatır.

MissingMemberException(String, Exception)

Sınıfın MissingMemberException yeni bir örneğini belirtilen bir hata iletisiyle ve bu özel durumun kök nedeni olan iç özel duruma başvuruyla başlatır.

MissingMemberException(String, String)

Belirtilen sınıf adı ve üye adıyla sınıfının yeni bir örneğini MissingMemberException başlatır.

Alanlar

ClassName

Eksik üyenin sınıf adını tutar.

MemberName

Eksik üyenin adını tutar.

Signature

Kayıp üyenin imzasını tutar.

Özellikler

Data

Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan bir anahtar/değer çifti koleksiyonu alır.

(Devralındığı yer: Exception)
HelpLink

Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar.

(Devralındığı yer: Exception)
HResult

Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar.

(Devralındığı yer: Exception)
InnerException

Exception Geçerli özel duruma neden olan örneği alır.

(Devralındığı yer: Exception)
Message

Sınıf adını, üye adını ve eksik üyenin imzasını gösteren metin dizesini alır.

Source

Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar.

(Devralındığı yer: Exception)
StackTrace

Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır.

(Devralındığı yer: Exception)
TargetSite

Geçerli özel durumu oluşturan yöntemini alır.

(Devralındığı yer: Exception)

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetBaseException()

Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan değerini döndürür Exception .

(Devralındığı yer: Exception)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo Nesneyi sınıf adı, üye adı, eksik üyenin imzası ve ek özel durum bilgileriyle ayarlar.

GetObjectData(SerializationInfo, StreamingContext)

Türetilmiş bir sınıfta geçersiz kılındığında, özel durum hakkındaki bilgilerle öğesini ayarlar SerializationInfo .

(Devralındığı yer: Exception)
GetType()

Geçerli örneğin çalışma zamanı türünü alır.

(Devralındığı yer: Exception)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli özel durumun dize gösterimini oluşturur ve döndürür.

(Devralındığı yer: Exception)

Ekinlikler

SerializeObjectState
Kullanımdan kalktı.

Bir özel durum, özel durum hakkında serileştirilmiş veriler içeren bir özel durum nesnesi oluşturmak üzere seri hale getirildiğinde gerçekleşir.

(Devralındığı yer: Exception)

Şunlara uygulanır

Ayrıca bkz.