invalid Cast

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steph

    #1

    invalid Cast

    Hello,

    I'm using COM object in an application. One method used give an object wich
    type is object.
    When I use a GetType on its, I have "System.Str ing[*]".

    I try to convert it to loop on the array of string but I have an exception
    (Invalid Cast Exception)

    Here is my code :


    myFormule = new Formule(); //Formule is a COM object
    object myTest = myFormule.GetEl ement;
    txtInfo.AppendT ext("object type: " + myTest.GetType( )); //<-- here I have a
    System.String[*]

    //convert
    string[] myTbl = (string[])myTest; // <-- here I have an exception


    ....

    What can I do to loop and get values from myTest ?

    thanks for your help

    Steph


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: invalid Cast

    Steph,

    That looks odd, to say the least. Can you provide the IDL or the type
    library (or the DLL itself) which has the definition of the interface with
    this method on it? Looking at that, it would be easier to determine what it
    is actually returning. One would expect the type of what is returned to be
    "String[]".


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Steph" <steph@nospampl ease.com> wrote in message
    news:OZ2v0t7nDH A.2772@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hello,
    >
    > I'm using COM object in an application. One method used give an object[/color]
    wich[color=blue]
    > type is object.
    > When I use a GetType on its, I have "System.Str ing[*]".
    >
    > I try to convert it to loop on the array of string but I have an exception
    > (Invalid Cast Exception)
    >
    > Here is my code :
    >
    >
    > myFormule = new Formule(); //Formule is a COM object
    > object myTest = myFormule.GetEl ement;
    > txtInfo.AppendT ext("object type: " + myTest.GetType( )); //<-- here I have[/color]
    a[color=blue]
    > System.String[*]
    >
    > //convert
    > string[] myTbl = (string[])myTest; // <-- here I have an exception
    >
    >
    > ...
    >
    > What can I do to loop and get values from myTest ?
    >
    > thanks for your help
    >
    > Steph
    >
    >[/color]


    Comment

    Working...