invoke a method by reflection£¬the method's parameters can not be ArrayList?

J

jerry051

I invoke a method by reflection, when this method's parameters is simple
type like int or string,the invoking is correct and secceed. But when the
parameters is ArrayList type, debuger tips me that meet
System.Reflection.TargetParameterCountException error, and parameters count
is not matching. please help me why happen this error,thanks a lot!
 
E

Erick

Here is your problem, the Invoke method overload you're using takes the
target object and an array or arguments. In your case you only have one
argument which is a object array.

Change:
object temp = myType.GetMethod("Exec").Invoke(myInstance, obj);

To:
object temp = myType.GetMethod("Exec").Invoke(myInstance,new object[]{
obj});


HTH
Erick Sgarbi
www.blog.csharpbox.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top