Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取反射.net中的MethodMissingException_C#_Reflection - Fatal编程技术网

C# 获取反射.net中的MethodMissingException

C# 获取反射.net中的MethodMissingException,c#,reflection,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 genera

我的代码读取方法是

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";
        }
    }
}
我想调用InvoiceProcessorTest类的ProcessTest方法

myType.GetMethods()
显示了类中的两个方法

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

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" }));

使用mytype.InvokeMember

什么是
submitoferType
?这里有一个简短但完整的示例非常有用。只需首先检查此项,您的第一个代码块将调用类
Processor.InvoiceProcessorTest
,但第二个代码块假定它是
名称空间.InvoiceProcessorTest
。然而,这将导致与您描述的不同的错误,因此我怀疑这些代码块中的一个与您使用的不同。@jan peter vos和@jon skeet我正在展示我的项目示例。请查找更新代码我在我的应用程序中使用了相同的代码我在这里发布了示例代码只需检查您是否使用了正确的(最新的)ProjectDLL.dll。我检查了你的代码,工作正常
Console.WriteLine((string)myType.InvokeMember(.........