mercredi 12 avril 2017

Invoke the method on the instance error 'Parameter count mismatch'

I am trying to call a function of a class dynamically on the bases of incoming querystring in controller using reflection.

class name: MyClass

function name: MyFunction in MyClass

My code so far

Type type = Type.GetType("MyNamespace.MyClass");
Object obj = Activator.CreateInstance(type);
MethodInfo methodInfo = type.GetMethod("MyFunction");
methodInfo.Invoke(obj, null);

methodInfo is getting correct function and its datatype but invoking the method on the instance obj above is giving following error.

System.Reflection.TargetParameterCountException: Parameter count mismatch.

Please help me solve this issue. Thanks





Aucun commentaire:

Enregistrer un commentaire