Home All Groups Group Topic Archive Search About

Reflection getting MissingMethodException

Author
20 Mar 2006 10:27 PM
brian.gabriel
I am trying to use reflection to dynamically call a method.  I have an
"interface" object that is inherited by the object that I am trying to
invoke.  The interface object contains virtual methods that throw a
custom NotImplemented exception.  The actual class overrides these
methods, the end goal is to loop through each method to see which ones
throw the NotImplemented exception.

Here is the code that I am using to dynamically invoke to method:

Type InterfaceType = typeof(Interfaces.MainInterface);
System.Runtime.Remoting.ObjectHandle hobj = null;
object[] arguments = new object[0];

hobj =
Activator.CreateInstance("Interfaces.MainClass1","Interfaces.MainClass1");
object result = InterfaceType
..InvokeMember("myMethod",BindingFlags.Instance|BindingFlags.Public|BindingFlags.InvokeMethod,null,hobj,arguments);

When I run the code I get a MissingMethodException exception saying it
can find method Interfaces.MainClass1.myMethod

Everything looks clean, any thoughts?

Thanks,

Brian
brian.gabr***@gmail.com

Author
21 Mar 2006 11:05 AM
Dmytro Lapshyn [MVP]
Hi Brian,

I am not sure InvokeMember can accept object handles. Can you please try
CreateInstanceAndUnwrap to get a real object reference and then supply the
obtained reference to InvokeMember instead of the "hobj" handle?

<brian.gabr***@gmail.com> wrote in message
Show quote
news:1142893665.261614.70000@u72g2000cwu.googlegroups.com...
>I am trying to use reflection to dynamically call a method.  I have an
> "interface" object that is inherited by the object that I am trying to
> invoke.  The interface object contains virtual methods that throw a
> custom NotImplemented exception.  The actual class overrides these
> methods, the end goal is to loop through each method to see which ones
> throw the NotImplemented exception.
>
> Here is the code that I am using to dynamically invoke to method:
>
> Type InterfaceType = typeof(Interfaces.MainInterface);
> System.Runtime.Remoting.ObjectHandle hobj = null;
> object[] arguments = new object[0];
>
> hobj =
> Activator.CreateInstance("Interfaces.MainClass1","Interfaces.MainClass1");
> object result = InterfaceType
> .InvokeMember("myMethod",BindingFlags.Instance|BindingFlags.Public|BindingFlags.InvokeMethod,null,hobj,arguments);
>
> When I run the code I get a MissingMethodException exception saying it
> can find method Interfaces.MainClass1.myMethod
>
> Everything looks clean, any thoughts?
>
> Thanks,
>
> Brian
> brian.gabr***@gmail.com
>
Author
21 Mar 2006 1:48 PM
brian.gabriel
I tried unwrapping the object and passing the actual reference, no
luck.

Thanks,

Brian
brian.gabr***@gmail.com

AddThis Social Bookmark Button