Casting returned object

  • Thread starter Thread starter Stuart Miles
  • Start date Start date
S

Stuart Miles

I have a 3rd party DLL with a function that has a return parameter of type
object.

After I make the call:

messagingClass.eGetUnreadMessages(ref myId, ref msgs);

when I look at it in the Locals window I get the following:

- msgs {System.Array} System.Object
[0,0] "AFPSDEV1" string
[0,1] "AFPSDEV1" string
[0,2] "AFPSDEV1" string
+ [1,0] {12002} System.Int32
+ [1,1] {12003} System.Int32
+ [1,2] {12004} System.Int32

This looks like an array of eMsgIdentType so I try and cast it to that

eMsgIdentType[] unreadMsgs = (eMsgIdentType[])msgs;

But I get the following error:

An unhandled exception of type 'System.InvalidCastException' occurred in
Serialization.exe

Additional information: Specified cast is not valid.

As a complete newbie to C# can somebody point me in the right direction.
 
Try IList instead. Then you should be able to use the standard someList[x]
to access elements

JIM
 
Try doing this:

MessageBox.Show(messagingClass.eGetUnreadMessages(ref myId, ref
msgs).GetType().FullName);

this should show you the type name of the class being returned. From there
you should be able to cast the result to the right type and get access to
the properties.


--
Thanks
Wayne Sepega
Jacksonville, Fl


"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
Try doing this:

MessageBox.Show(messagingClass.eGetUnreadMessages(ref myId, ref
msgs).GetType().FullName);

this should show you the type name of the class being returned. From there
you should be able to cast the result to the right type and get access to
the properties.

Thank you, msgs.GetType().FullName returned System.Object[,] which did the
trick nicely.
 
Back
Top