Dario Russi [MS]
11/22/2002 11:59:00 PM
Is elemen.obj in the call method.Invoke(element.obj,par); an instance of the
type where void perform(IEvent evnt); is defined?
I think you can get that exception if both the target or the args cannot
convert to the proper type.
Your arg checking seems quite well protected, I wonder if the "this"
provided is correct.
HTH
dario
"Robert L" <lario@*nospam*Diemsolutions.com> wrote in message
news:OCb33xKkCHA.2600@tkmsftngp12...
> I've been beating my head agaist the wall for days now on this problem.
the
> Following code throws this exception : "Object type cannot be converted to
> target type". There is only one method called perform and has the
following
> signature:
>
> void perform(IEvent evnt);
>
> to isolate the problem I put the if statement around the invoke to ensure
> that I had the correct method and was passing the correct type to the
> invoke.
>
> I am stuck....
>
> method = element.type.GetMethod("perform");
>
> System.Reflection.ParameterInfo[] paramInfos = method.GetParameters();
>
> if(paramInfos[0].ParameterType.Name.Equals("IEvent") &&
>
> paramInfos.Length == 1 &&
>
> evnt is IEvent)
>
> {
>
> object [] par = new object[] {(IEvent) evnt};
>
> return method.Invoke(element.obj,par);
>
>
> }
>
>
>