【发布时间】:2016-08-06 17:40:50
【问题描述】:
我正在学习 C#,目前在后期绑定章节。我为测试编写了以下内容,但它会生成 MissingMethodException。我加载了一个自定义私有 DLL 并成功调用了一个方法,然后我尝试对 GAC DLL 执行相同操作,但失败了。
不知道下面的代码有什么问题:
//Load the assembly
Assembly dll = Assembly.Load(@"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ");
//Get the MessageBox type
Type msBox = dll.GetType("System.Windows.Forms.MessageBox");
//Make an instance of it
object msb = Activator.CreateInstance(msBox);
//Finally invoke the Show method
msBox.GetMethod("Show").Invoke(msb, new object[] { "Hi", "Message" });
【问题讨论】:
-
MessageBox类没有公共构造函数,应该通过它的静态方法使用。
标签: c# late-binding missingmethodexception