什么是MissingMethodException

试图动态访问不存在的方法时引发的异常。

继承

说明

通常, 如果代码尝试访问不存在的类方法, 则会生成编译错误。 MissingMethodException旨在处理尝试动态访问未通过其强名称引用的程序集的已重命名或已删除方法的情况。 MissingMethodException当依赖程序集中的代码尝试访问已修改的程序集中缺少的方法时, 将引发。

HRESULT

MissingMethodException使用具有值0x80131513 的 HRESULT COR_E_MISSINGMETHOD。

示例

此示例演示当你尝试使用反射来调用不存在的方法并访问不存在的字段时会发生的情况。 应用程序通过捕获MissingMethodException、 MissingFieldException和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^>{});
}
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.

最新文章

  1. 旺财速啃H5框架之Bootstrap(三)
  2. Maven命令行使用:mvn clean package(打包)
  3. [poj2247] Humble Numbers (DP水题)
  4. ThinkPHP 3.2.3(二)配置
  5. (Hibernate进阶)Hibernate映射——多对多关联映射(八)
  6. iOS 判断字符串是否为空
  7. 查询指定网段可用IP脚本
  8. nodejs获取客户端IP Address
  9. Android 2.x中使用actionbar - Actionbarsherlock (2)
  10. YII Framework学习教程-YII的日志
  11. iOS8中的UIAlertController
  12. codeforces 391C3 - The Tournament
  13. 工作中用到的Jquery特效
  14. myPagination5.0 分页简单实例
  15. html combobox select控件设置默认选项
  16. [转]异常:android.os.NetworkOnMainThreadException
  17. Android的cookie的接收和发送
  18. 安全圈玩起了直播,&quot;学霸”带你玩转CTF
  19. 剑指Offer-- 翻转链表 (python版)
  20. c++ 格式字符串说明

热门文章

  1. jquery加载数据时显示loading加载动画特效
  2. linux 查询某个时间段的日志
  3. NMS的实现代码详解
  4. mysql-多表联查(实例)
  5. Java之路---Day03
  6. BFC特性及其简单应用
  7. 笔谈HTTP Multipart POST请求上传文件
  8. java系统化基础-day02-运算符、选择结构、循环结构
  9. css浮动float详解
  10. 泛微 e-cology OA 远程代码执行漏洞复现