Thursday 15 March 2012

c# - Get return value after invoking a method from dll using reflection -


I am loading a DLL with reflection and trying to use a method which is List & lt; CustomType & gt; . How do I open a method and get return value? I tried it but say that entry point not found exception .

  MethodWho [] info = classType.GetMethods (); MethodInfo method = mInfo.FirstOrDefault (c = & gt; c.Name == "GetDetails"); Object value = method.Invoke (classInstance, new object [] {param1}); Exception to   

value entry point not found .

  assembly assembly = assembly.LoadFile (@ "assembly location"); // You can change the type of assembly you 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 & lt; customType & gt;) methodInfo.Invoke (classObject, new object [] {param1});   

Based on some changes it may be necessary whether your class is stable and if your constructor takes any parameters.

No comments:

Post a Comment