什么是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.

关于System.MissingMethodException异常的更多相关文章

  1. 【EF框架异常】System.MissingMethodException:“找不到方法:“System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration

    最近调试EF的时候遇到下面这个问题 System.MissingMethodException:“找不到方法:“System.Data.Entity.ModelConfiguration.Config ...

  2. 关于SubSonic3.0插件使用SqlQuery或Select查询时产生的System.NullReferenceException异常修复

    早上在编写执行用例时,突然爆异常System.NullReferenceException: 未将对象引用设置到对象的实例 执行代码:

  3. 关于SubSonic3.0查询或更新时出现System.NullReferenceException异常的处理

    在调试程序时,同事发现添加记录时,出现了System.NullReferenceException异常 DictBase dict = new DictBase();    dict.DictCode ...

  4. 关于System.TypeInitializationException异常

    什么是System.TypeInitializationException 作为类初始值设定项引发的异常的包装器而引发的异常. 继承 Object Exception SystemException ...

  5. 异常详细信息: System.MissingMethodException: 无法创建抽象类。

    asp.net mvc 在使用post向后端传送json数据时报异常,在路由配置中添加如下即可 public static void RegisterRoutes(RouteCollection ro ...

  6. .Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)

    最近在开发一个.Net程序,其中涉及到对com组件的调用,或者第三方DLL调用, 在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序,或者WPF程序中,继续执行 ...

  7. C# winform单元格的formatted值的类型错误 DataGridView中CheckBox列运行时候System.FormatException异常

    在DataGridView手动添加了CheckBox列;在窗体Show的时候,遇到一个错误:错误如下: DataGridView中发生一下异常:System.FormatException:单元格的F ...

  8. [.Net]System.OutOfMemoryException异常

    1. 一个异常情景 加载15000条等高线,平均每条线有400个点到三维球上,等待时间太长.而且可能会报内存异常. 2. 不错的分析 http://wenku.baidu.com/view/14471 ...

  9. log4j:WARN Please initialize the log4j system properly. 异常解决

    log4j:WARN Please initialize the log4j system properly. 这个异常很少遇到,咋一看,原来是没有配置logger4j的配置文件 问题解决方法: 传统 ...

随机推荐

  1. 【LEETCODE】65、字符分类,medium&easy级别,题目:20、647、3

    今天的字符类还比较简单 package y2019.Algorithm.str.easy; import java.util.HashMap; import java.util.Map; import ...

  2. unity---为什么用Time.deltaTime * speed 表示每秒移动的距离的理解

    Time.deltaTime:代表时间增量,即从上一帧到当前帧消耗的时间, 这个值是动态变化的. dt 表示 deltaTime. 假如 1s渲染10帧,沿X轴方向的移动速度 speed = 10m/ ...

  3. SnowflakeIdWorker

    /** * Twitter_Snowflake<br> * SnowFlake的结构如下(每部分用-分开):<br> * 0 - 0000000000 0000000000 0 ...

  4. Eclipse创建ssm项目

    1.创建Maven项目 2.勾选上面的 3.打成war包的形式 4.配置webapp.xml  Project Facets——Dynamic Wed Module 2.5 ——然后点击下面的提示 5 ...

  5. java之mybatis之动态sql

    1. if 判读条件是否满足,满足将会把 sql 语句加上. <select id="findUser" parameterType="Map" resu ...

  6. 什么是SAP Intelligent Robitic Process Automation - iRPA

    所谓智慧企业,一个特征就是具备将复杂但低附加值的重复流程通过自动化的方式完成的能力.通过自动化,从而将宝贵的人力资源投入到更高附加值的工作中去,比如提供产品和服务的品质,提升用户体验.SAPGUI时代 ...

  7. laravel项目中通过nvmw安装node.js和npm 开发环境-- windows版

    windows版本安装 此教程执行的时候,网速一定要好.不然可能出现各种错误. 如果本文对你有用,请爱心点个赞,提高排名,帮助更多的人.谢谢大家!❤ git clone nvmw  直接从 githu ...

  8. CentOS7安装MySQL5.7及Tomcat8.5

    在CentOS7服务器上部署FR项目应用 一.安装CentOS-7_x86_64 1.CentOS7:带GUI的服务器(FTP服务器.JAVA平台.兼容性程序库.开发工具.安全性工具.系统管理工具): ...

  9. AD10生成Gerber文件详细步骤

    参考:https://wenku.baidu.com/view/faf0363c195f312b3069a5d2.html

  10. uiautomator2+python自动化测试1-环境准备

    前言 uiautomator是Google提供的用来做安卓自动化测试的一个Java库.功能很强,可以对第三方App进行测试,获取屏幕上任意一个APP的任意一个控件属性,并对其进行任意操作,但有两个缺点 ...