[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Object type cannot be converted to target type

Robert L

11/20/2002 4:49:00 PM

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);


}



2 Answers

Robert Jeppesen

11/20/2002 5:13:00 PM

0

Don't know if this helps but you're doing
return method.Invoke(element.obj,par);
where the perform method doesn't have a return type.

--
Robert Jeppesen
MindCom AB
http://www.m...

"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);
>
>
> }
>
>
>


Dario Russi [MS]

11/22/2002 11:59:00 PM

0

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);
>
>
> }
>
>
>