在Reflection .net中获取MethodMissingException

时间:2011-06-15 07:58:43

标签: c# reflection

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Processor
{
    public class InvoiceProcessorTest
    {
        public void Process(String entity)
        {
            GenerateInvoice generateInvoice = new GenerateInvoice();
            generateInvoice.Process(entity);
        }
        public string ProcessTest(String str)
        {
            return "testString";
        }
    }
}

我的读取方法代码是

Assembly processorAssembly = Assembly.LoadFile("ProjectDLL.dll");
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

Type myType= processorAssembly.GetType("Processor.InvoiceProcessorTest");
object myObj = Activator.CreateInstance(myType);

Console.WriteLine((string)myType.InvokeMember("ProcessTest", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, myObj , new object[] { "Pramod" }));

我想调用InvoiceProcessorTest类的ProcessTest方法。

myType.GetMethods() 向我展示了该课程的两种方法。

但是当我调用Invmber时,它会返回一个缺少的MethodException。找不到Namespace.InvoiceProcessorTest.ProcessTest

1 个答案:

答案 0 :(得分:0)

Console.WriteLine((string)myType.InvokeMember(.........

使用mytype.InvokeMember