You invoke it like any other method through reflection. except that the returned value will be copied back into the parameter array so you can access it from the calling function.
Eg;
class Program
{
delegate int Run(int a, int b, out int sum);
private static Run invoke;
static void Main()
{
Assembly asm = Assembly.LoadFrom(@"C:\MyApplications\MathLibrary.dll");
Type simpleMath = asm.GetType("MathLibrary.SimpleMath");
object obj = Activator.CreateInstance(simpleMath);
MethodInfo m = simpleMath.GetMethod("Add");
invoke = (Run)Delegate.CreateDelegate(typeof(Run), obj, m);
int sum;
sum = invoke(10, 20, out sum);
}
}
Or you can try this
Assembly asm = Assembly.LoadFrom(@"C:\MyApplications\MathLibrary.dll");
Type simpleMath = asm.GetType("MathLibrary.SimpleMath");
object obj = Activator.CreateInstance(simpleMath);
MethodInfo m = simpleMath.GetMethod("Add");
int sum;
sum = m.Invoke(obj,new object[]{10, 20, sum});
Please vote and mark as solution if this solves your problem thanks.