MissingFieldException Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Pengecualian yang dilemparkan ketika ada upaya untuk mengakses bidang yang tidak ada secara dinamis. Jika bidang di pustaka kelas telah dihapus atau diganti namanya, kompilasi ulang rakitan apa pun yang mereferensikan pustaka tersebut.
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
- Warisan
- Warisan
- Atribut
- Penerapan
Contoh
Contoh ini menunjukkan apa yang terjadi jika Anda mencoba menggunakan pantulan untuk memanggil metode yang tidak ada dan mengakses bidang yang tidak ada. Aplikasi pulih dengan menangkap MissingMethodException, , MissingFieldExceptiondan 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.
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.
Keterangan
Biasanya kesalahan kompilasi dihasilkan jika kode mencoba mengakses anggota kelas yang tidak ada. MissingFieldException dirancang untuk menangani kasus di mana upaya dilakukan untuk mengakses bidang rakitan yang diganti namanya atau dihapus secara dinamis yang tidak direferensikan dengan nama kuatnya. MissingFieldException dilemparkan ketika kode dalam rakitan dependen mencoba mengakses bidang yang hilang dalam rakitan yang dimodifikasi.
MissingFieldException menggunakan COR_E_MISSINGFIELD HRESULT, yang memiliki nilai 0x80131511.
Untuk daftar nilai properti awal untuk instans MissingFieldException, lihat MissingFieldException konstruktor.
Konstruktor
MissingFieldException() |
Menginisialisasi instans baru kelas MissingFieldException. |
MissingFieldException(SerializationInfo, StreamingContext) |
Menginisialisasi instans MissingFieldException baru kelas dengan data berseri. |
MissingFieldException(String) |
Menginisialisasi instans MissingFieldException baru kelas dengan pesan kesalahan yang ditentukan. |
MissingFieldException(String, Exception) |
Menginisialisasi instans MissingFieldException baru kelas dengan pesan kesalahan yang ditentukan dan referensi ke pengecualian dalam yang merupakan penyebab pengecualian ini. |
MissingFieldException(String, String) |
Menginisialisasi instans MissingFieldException baru kelas dengan nama kelas dan nama bidang yang ditentukan. |
Bidang
ClassName |
Memegang nama kelas anggota yang hilang. (Diperoleh dari MissingMemberException) |
MemberName |
Memegang nama anggota yang hilang. (Diperoleh dari MissingMemberException) |
Signature |
Memegang tanda tangan anggota yang hilang. (Diperoleh dari MissingMemberException) |
Properti
Data |
Mendapatkan kumpulan pasangan kunci/nilai yang memberikan informasi tambahan yang ditentukan pengguna tentang pengecualian. (Diperoleh dari Exception) |
HelpLink |
Mendapatkan atau mengatur tautan ke file bantuan yang terkait dengan pengecualian ini. (Diperoleh dari Exception) |
HResult |
Mendapatkan atau menetapkan HRESULT, nilai numerik berkode yang ditetapkan ke pengecualian tertentu. (Diperoleh dari Exception) |
InnerException |
Mendapatkan instans Exception yang menyebabkan pengecualian saat ini. (Diperoleh dari Exception) |
Message |
Mendapatkan string teks yang memperlihatkan tanda tangan bidang yang hilang, nama kelas, dan nama bidang. Properti ini bersifat hanya baca. |
Source |
Get dan set nama aplikasi atau objek yang menyebabkan kesalahan. (Diperoleh dari Exception) |
StackTrace |
Mendapatkan representasi string dari bingkai langsung pada tumpukan panggilan. (Diperoleh dari Exception) |
TargetSite |
Mendapatkan metode yang melemparkan pengecualian saat ini. (Diperoleh dari Exception) |
Metode
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetBaseException() |
Ketika ditimpa di kelas turunan, mengembalikan Exception yang merupakan akar penyebab dari satu atau beberapa pengecualian berikutnya. (Diperoleh dari Exception) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetObjectData(SerializationInfo, StreamingContext) |
SerializationInfo Mengatur objek dengan nama kelas, nama anggota, tanda tangan anggota yang hilang, dan informasi pengecualian tambahan. (Diperoleh dari MissingMemberException) |
GetType() |
Mendapatkan jenis runtime instans saat ini. (Diperoleh dari Exception) |
MemberwiseClone() |
Membuat salinan dangkal dari yang saat ini Object. (Diperoleh dari Object) |
ToString() |
Membuat dan mengembalikan representasi string dari pengecualian saat ini. (Diperoleh dari Exception) |
Acara
SerializeObjectState |
Kedaluwarsa.
Terjadi ketika pengecualian diserialisasikan untuk membuat objek status pengecualian yang berisi data berseri tentang pengecualian. (Diperoleh dari Exception) |