473,320 Members | 1,936 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,320 software developers and data experts.

Reflection Question

I'm trying to invoke a method that returns a value (actually a Panel), but i
keep getting an error:

System.Reflection.TargetException was unhandled
Message="Object does not match target type."

Here's the code:

MethodInfo methodInfo = typeChannelPanel.GetMethod("CreateNavPanel");

Panel o_Panel = (Panel)methodInfo.Invoke(methodInfo, null);

I've tried creating it as an Object and i get the same error. The
CreateNavPanel returns a Panel, which i then need to add to the main form.
What am i missing here?

Dec 1 '05 #1
2 4500
The first parameter of methodInfo.Invoke is the target object i.e. if you
were doing it in "normal" code

myPanel.CreateNavPanel();

then the equivalent in reflection would be

methodInfo.Invoke(myPanel, null);

Does that make sense? The only exception is for static methods, where you
can pass null into the first argument.

Your code attempts to execute the method on the methodInfo object, hence the
error.

Marc

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:u6**************@TK2MSFTNGP14.phx.gbl...
I'm trying to invoke a method that returns a value (actually a Panel), but
i keep getting an error:

System.Reflection.TargetException was unhandled
Message="Object does not match target type."

Here's the code:

MethodInfo methodInfo = typeChannelPanel.GetMethod("CreateNavPanel");

Panel o_Panel = (Panel)methodInfo.Invoke(methodInfo, null);

I've tried creating it as an Object and i get the same error. The
CreateNavPanel returns a Panel, which i then need to add to the main form.
What am i missing here?

Dec 1 '05 #2
Marc,

Thanks...figured it out.

Cheers.
"Marc Gravell" <mg******@rm.com> wrote in message
news:O3**************@TK2MSFTNGP15.phx.gbl...
The first parameter of methodInfo.Invoke is the target object i.e. if you
were doing it in "normal" code

myPanel.CreateNavPanel();

then the equivalent in reflection would be

methodInfo.Invoke(myPanel, null);

Does that make sense? The only exception is for static methods, where you
can pass null into the first argument.

Your code attempts to execute the method on the methodInfo object, hence
the error.

Marc

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:u6**************@TK2MSFTNGP14.phx.gbl...
I'm trying to invoke a method that returns a value (actually a Panel),
but i keep getting an error:

System.Reflection.TargetException was unhandled
Message="Object does not match target type."

Here's the code:

MethodInfo methodInfo = typeChannelPanel.GetMethod("CreateNavPanel");

Panel o_Panel = (Panel)methodInfo.Invoke(methodInfo, null);

I've tried creating it as an Object and i get the same error. The
CreateNavPanel returns a Panel, which i then need to add to the main
form. What am i missing here?


Dec 1 '05 #3

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

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
1
by: Pieter Breed | last post by:
Hi All, I am trying to use the attribute/reflection system to as much potential as I can think of, but I've run into a snag. I would appreciate it if someone would point me in the right...
5
by: heddy | last post by:
I understand that reflection allows me to discover the metadata of a class at runtime (properties, methods etc). What I don't understand is where this is useful. For example: If I am the sole...
5
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, is it faster to access the fields from an object directly by using reflection than accessing them by their properties using reflection? Thanks Christian
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.