473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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!
Nov 17 '05 #1
5 2354
jerry051 wrote:
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!


Please show us the code you are using when you invoke the method.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2
Hi,

Show the code, you should use the very same approach , create an object[]
and construct it with your parameters. it should work fine
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jerry051" <be******@sogou.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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!

Nov 17 '05 #3
jerry051 wrote:

Okay. The reason for your problem lies in these two lines:
public object Exec(ArrayList parameters)
The Exec method is declared to receive one parameter: An ArrayList.
object temp = myType.GetMethod("Exec").Invoke(myInstance, new
object[]{"a","b","c","d","e"}); //this will cause exception that i
describing ahead!


But your call passes five parameters, not one. This doesn't fit,
obviously. Maybe you were expecting some automagical conversion to take
place, well, bad luck in that case :-)

You'll have to do one of two things. You can (a) create an arraylist to
pass to your method:

ArrayList list = new ArrayList(new string[] {
"a","b","c","d","e" });
object temp = myType.GetMethod("Exec").Invoke(myInstance,
new object[]{ list });

Or your can change your Exec method to take a list of parameters instead
of the arraylist:

public object Exec(params object[] parameters) {
...
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #4
Oliver Sturm: hi,thank u very much ,i have dealed this proplem :)
you are right, it's my inattention with parameters pass.
"jerry051" <be******@sogou.com> дÈëÓʼþ
news:uV**************@TK2MSFTNGP14.phx.gbl...
I accept your advise, changed my method parameters ,but it still report
same error! could you help me to read source code (accessory ) look for
where is incorrect?

"Oliver Sturm" <ol****@sturmnet.org> дÈëÓʼþ
news:%2****************@TK2MSFTNGP12.phx.gbl...
jerry051 wrote:

Okay. The reason for your problem lies in these two lines:
public object Exec(ArrayList parameters)


The Exec method is declared to receive one parameter: An ArrayList.
object temp = myType.GetMethod("Exec").Invoke(myInstance, new
object[]{"a","b","c","d","e"}); //this will cause exception that i
describing ahead!


But your call passes five parameters, not one. This doesn't fit,
obviously. Maybe you were expecting some automagical conversion to take
place, well, bad luck in that case :-)

You'll have to do one of two things. You can (a) create an arraylist to
pass to your method:

ArrayList list = new ArrayList(new string[] {
"a","b","c","d","e" });
object temp = myType.GetMethod("Exec").Invoke(myInstance,
new object[]{ list });

Or your can change your Exec method to take a list of parameters instead
of the arraylist:

public object Exec(params object[] parameters) {
...
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog


Nov 17 '05 #5
Good to hear you figured it out.

Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: S Shulman | last post by:
Hi I am looking for a method that allows calling a method that will be executed by the main application thread bu will be called from any thread that I create manually. (I think that...
1
by: boxim | last post by:
hi all, I'm having a few problems whereby my application is hanging when using the Invoke method of a form's control. Basically, when a user clicks a button on the form, it calls a remote...
1
by: David | last post by:
How can I Invoke method in my application from other application? Also how can I expose method from Windows Application?
1
by: A.M-SG | last post by:
Hi, I have a web service with two soap extensions enabled on it. When I run the default IIS method invoke page, the invoke button bypasses all my soap extensions. But when I call the...
11
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register...
1
by: yxq | last post by:
Hello, I want to start or stop the drives using WMI class Win32_SystemDriver, i do not know how to invoke the method in this class(for example StartService, StopService... ). The WMI class link:...
0
by: truthbajaj | last post by:
Hi, I am using Oracle 9i and Unix on my system and trying to execute a UNIX shell command through external procedure in C. I created a shared lib (libextproc.so) for the following function. ...
6
by: Dom | last post by:
I'm teaching myself about delegates and the Invoke method, and I have a few newbie questions for the gurus out there: Here are some CSharp statements: 1. public delegate void MyDelegate (int k,...
0
by: Sebouh | last post by:
Hi guys. I was messing with Threading and stuff, and i have reached a point where i'm not sure what's causing the current behavior. Here's the code: Public Class Form1 Private Sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.