我正在学习 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" });