MissingMethodException Klasa
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Wyjątek zgłaszany w przypadku próby dynamicznego uzyskania dostępu do metody, która nie istnieje.
public ref class MissingMethodException : MissingMemberException
public class MissingMethodException : MissingMemberException
[System.Serializable]
public class MissingMethodException : MissingMemberException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class MissingMethodException : MissingMemberException
type MissingMethodException = class
inherit MissingMemberException
type MissingMethodException = class
inherit MissingMemberException
interface ISerializable
[<System.Serializable>]
type MissingMethodException = class
inherit MissingMemberException
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MissingMethodException = class
inherit MissingMemberException
interface ISerializable
Public Class MissingMethodException
Inherits MissingMemberException
- Dziedziczenie
- Dziedziczenie
-
MissingMethodException
- Atrybuty
- Implementuje
Przykłady
W tym przykładzie pokazano, co się stanie w przypadku próby użycia odbicia w celu wywołania metody, która nie istnieje i uzyskania dostępu do pola, które nie istnieje. Aplikacja odzyskuje dane, przechwytując wartości MissingMethodException, MissingFieldExceptioni 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.
Uwagi
Zwykle jest generowany błąd kompilacji, jeśli kod próbuje uzyskać dostęp do nieistniejących metod klasy. MissingMethodException program jest przeznaczony do obsługi przypadków, w których podejmowana jest próba dynamicznego uzyskiwania dostępu do zmienionej lub usuniętej metody zestawu, do którego nie odwołuje się silna nazwa. MissingMethodException jest zgłaszany, gdy kod w zestawie zależnym próbuje uzyskać dostęp do brakującej metody w zmodyfikowanym zestawie.
MissingMethodException używa COR_E_MISSINGMETHOD HRESULT, który ma wartość 0x80131513.
Aby uzyskać listę początkowych wartości właściwości dla wystąpienia MissingMethodException, zapoznaj się z konstruktorami MissingMethodException.
Dokładny czas ładowania statycznie przywoływanej metody jest nieokreślony. Ten wyjątek może zostać zgłoszony przed rozpoczęciem wykonywania metody, która odwołuje się do brakującej metody.
Konstruktory
| Nazwa | Opis |
|---|---|
| MissingMethodException() |
Inicjuje nowe wystąpienie klasy MissingMethodException. |
| MissingMethodException(SerializationInfo, StreamingContext) |
Przestarzałe.
Inicjuje MissingMethodException nowe wystąpienie klasy z serializowanymi danymi. |
| MissingMethodException(String, Exception) |
Inicjuje nowe wystąpienie MissingMethodException klasy z określonym komunikatem o błędzie i odwołaniem do wyjątku wewnętrznego, który jest przyczyną tego wyjątku. |
| MissingMethodException(String, String) |
Inicjuje MissingMethodException nowe wystąpienie klasy o określonej nazwie klasy i nazwie metody. |
| MissingMethodException(String) |
Inicjuje nowe wystąpienie klasy MissingMethodException z określonym komunikatem o błędzie. |
Pola
| Nazwa | Opis |
|---|---|
| ClassName |
Przechowuje nazwę klasy brakującego elementu członkowskiego. (Odziedziczone po MissingMemberException) |
| MemberName |
Przechowuje nazwę brakującego elementu członkowskiego. (Odziedziczone po MissingMemberException) |
| Signature |
Przechowuje podpis brakującego elementu członkowskiego. (Odziedziczone po MissingMemberException) |
Właściwości
| Nazwa | Opis |
|---|---|
| Data |
Pobiera kolekcję par klucz/wartość, które zapewniają dodatkowe informacje zdefiniowane przez użytkownika dotyczące wyjątku. (Odziedziczone po Exception) |
| HelpLink |
Pobiera lub ustawia link do pliku pomocy skojarzonego z tym wyjątkiem. (Odziedziczone po Exception) |
| HResult |
Pobiera lub ustawia HRESULT, zakodowaną wartość liczbową przypisaną do określonego wyjątku. (Odziedziczone po Exception) |
| InnerException |
Exception Pobiera wystąpienie, które spowodowało bieżący wyjątek. (Odziedziczone po Exception) |
| Message |
Pobiera ciąg tekstowy z nazwą klasy, nazwą metody i podpisem brakującej metody. Ta właściwość jest tylko do odczytu. |
| Source |
Pobiera lub ustawia nazwę aplikacji lub obiektu, który powoduje błąd. (Odziedziczone po Exception) |
| StackTrace |
Pobiera reprezentację ciągu natychmiastowych ramek na stosie wywołań. (Odziedziczone po Exception) |
| TargetSite |
Pobiera metodę, która zgłasza bieżący wyjątek. (Odziedziczone po Exception) |
Metody
| Nazwa | Opis |
|---|---|
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
| GetBaseException() |
Po zastąpieniu w klasie pochodnej funkcja zwraca Exception główną przyczynę co najmniej jednego kolejnego wyjątku. (Odziedziczone po Exception) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Przestarzałe.
SerializationInfo Ustawia obiekt z nazwą klasy, nazwą składowej, podpisem brakującego elementu członkowskiego i dodatkowymi informacjami o wyjątku. (Odziedziczone po MissingMemberException) |
| GetType() |
Pobiera typ środowiska uruchomieniowego bieżącego wystąpienia. (Odziedziczone po Exception) |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Object. (Odziedziczone po Object) |
| ToString() |
Tworzy i zwraca reprezentację ciągu bieżącego wyjątku. (Odziedziczone po Exception) |
Zdarzenia
| Nazwa | Opis |
|---|---|
| SerializeObjectState |
Przestarzałe.
Występuje, gdy wyjątek jest serializowany w celu utworzenia obiektu stanu wyjątku zawierającego serializowane dane dotyczące wyjątku. (Odziedziczone po Exception) |