Using InvokeMember to invoke a method

G

Guest

I'm having a problem with late binding. I'm able to create an instance of a class dynamically at runtime and set a property, as in the following

EventCollectionFilterType.InvokeMember("EventGUID", BindingFlags.SetProperty, null, oEventCollectionFilter, paramEventGUIDObject)

However, invoking a method using the following doesn't work, with a runtime error being generated, compaining that it cannot find the method

oEvent = EventCollectionType.InvokeMember("Item", BindingFlags.Public | BindingFlags.InvokeMethod, null, oEventCollection, paramItemObject)

I've checked the method, and it has a public modifier, as expected, and is visible when explicitly creating an object of that type in the usual way. What am I doing wrong?

Martin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Item looks rather as a property (or even as an indexer in C#) than as a
method. If this is the case, try invoking "get_Item" or "set_Item" methods.
You can also examine the assembly containing the EventCollectionFilter class
with the ILDASM tool to find out the exact name of the method.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Martin Lee said:
I'm having a problem with late binding. I'm able to create an instance of
a class dynamically at runtime and set a property, as in the following:
EventCollectionFilterType.InvokeMember("EventGUID",
BindingFlags.SetProperty, null, oEventCollectionFilter,
paramEventGUIDObject);
However, invoking a method using the following doesn't work, with a
runtime error being generated, compaining that it cannot find the method:
oEvent = EventCollectionType.InvokeMember("Item", BindingFlags.Public |
BindingFlags.InvokeMethod, null, oEventCollection, paramItemObject);
I've checked the method, and it has a public modifier, as expected, and is
visible when explicitly creating an object of that type in the usual way.
What am I doing wrong?!
 

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

Top