5

I am loading a dll using reflection and trying to invoke a method that returns a List<customType>. How do I invoke a method and get the return values. I tried this but says 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});

values has the exception entry point not found.

Virus
  • 3,215
  • 7
  • 29
  • 46

1 Answers1

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

A few alterations might be required depending on if your class is static or not and if your constructor takes any parameters.

coolmine
  • 4,427
  • 2
  • 33
  • 45
  • What is this answer suppose to address? – leppie Mar 27 '13 at 06:41
  • Depending on what the problem is the OP is having, hard to say due to the lack of info but it seems to be an issue with the way the assembly is being load, hence the detailed example. – coolmine Mar 27 '13 at 06:42
  • If the OP already has the class type, how can the assembly not be loaded correctly? – leppie Mar 27 '13 at 06:44
  • Hard to say with only 3 lines of code and no stack trace. The above example works properly in case he/she needs an alternative. Other than that I can just update/delete the answer an soon as we have more information. – coolmine Mar 27 '13 at 06:45