5

我正在使用反射加载 dll 并尝试调用返回List<customType>. 如何调用方法并获取返回值。我试过这个,但说entry point not found exception

MethodInfo[] info= classType.GetMethods();
MethodInfo method = mInfo.FirstOrDefault(c => c.Name == "GetDetails");
object values = method.Invoke(classInstance, new object[] { param1});

价值观有例外entry point not found

4

1 回答 1

7
Assembly assembly = Assembly.LoadFile(@"assembly location");    // you can change the way you load the assembly
Type type = assembly.GetType("mynamespace.NameOfTheClass");                                       
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
object classObject = constructor.Invoke(new object[] { });

MethodInfo methodInfo = type.GetMethod("GetDetails");
var returnValue = (List<customType>)methodInfo.Invoke(classObject, new object[] { param1});

根据您的类是否为静态以及您的构造函数是否采用任何参数,可能需要进行一些更改。

于 2013-03-27T06:17:07.773 回答