Arraylist Copyto() InvalidCastException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pengbsam@yahoo.com

    #1

    Arraylist Copyto() InvalidCastException

    Hello All:
    Having a problem with arraylist.copyt o function. And here's a
    sample of my code in C#:
    In global-->
    public struct point
    {
    int x;
    string y;

    }


    static public point point;
    static public point pointarray[];
    static public Arraylist myal = new Arraylist();

    in sub_function -->
    for (i=0; i< some limites; i++)
    {
    global.point[i].x = some limites.some value;
    global.point[i].y = some limites.some string;
    global.myal.Add (global.point);



    }


    in Main function -->

    int a;
    string b;


    global.pointarr ay = new global.point[global.myal.Cou nt];
    global.myal.Cop yto(pointarray) ;
    for (i=0; i<global.myal.c ount; i++)
    {
    a = pointarray[i].x;
    b = pointarray[i].y;



    }


    global.myal.Cle ar();
    pointarray = null;

    This is basically the logic of the steps that I am trying to make a
    dynamic array struct, of course I understand there are different ways
    of doing this, but this one seems easiest if I was to pick and choose
    what needed to be inserted into my arraylist in main / sub function. It

    works fine on my computer (xp pro .net 2.0), however it doesn't work on

    my company's server computer (running server2003.net 2.0) Saying there
    there is a casting exception on the global.myal.Cop yto(pointarray)
    statement. I spend a lot of time trying to understand why this differ
    from machine to machine. But came up with nothing in MSDN or other
    resources. Have anyone done something like this? Please let me know!!
    Thank You!


    Also, it keep on telling me that I have a casting problem, so I tried
    to explicitly cast the array out of arraylist instead of copyto()..
    Doesn't work either. Any ideas how to do that? Very much appreciated
    it!!

  • Jon Shemitz

    #2
    Re: Arraylist Copyto() InvalidCastExce ption

    pengbsam@yahoo. com wrote:
    in Main function -->
    global.pointarr ay = new global.point[global.myal.Cou nt];
    global.myal.Cop yto(pointarray) ;
    works fine on my computer (xp pro .net 2.0), however it doesn't work on
    my company's server computer (running server2003.net 2.0) Saying there
    there is a casting exception on the global.myal.Cop yto(pointarray)
    statement.
    Are the main method and the global class (struct?) in the same
    assembly? Or is "global" in a library? If the latter, is it possible
    that there is a version mismatch between what you're compiling with
    and testing against on your development machine and what you're using
    at runtime on the server?

    --

    ..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
    Delphi skills make .NET easy to learn In print, in stores.

    Comment

    • pengbsam@yahoo.com

      #3
      Re: Arraylist Copyto() InvalidCastExce ption

      Sorry to say, I am not sure what do you mean. It's in the same C#
      project file? It's not from another DLL or calling another class! Is
      that same Assembly?

      Comment

      • Jon Shemitz

        #4
        Re: Arraylist Copyto() InvalidCastExce ption

        pengbsam@yahoo. com wrote:
        Sorry to say, I am not sure what do you mean. It's in the same C#
        project file? It's not from another DLL or calling another class! Is
        that same Assembly?
        Yes, though I feel sort of obliged to point out that, in general,
        you're not going to get much response to such very basic questions.
        Few people are going to take the time to answer something that you
        could easily Google, or answer via the VS help system, or even by
        checking the index of just about any basic .NET book. For example, I'm
        only answering that because I tried to answer your original query.

        To get back to that, if it's not some sort of version mismatch, I'm
        not really sure why it would run on your development system and not on
        a server. It might help if you posted compilable code, not your
        snippets.

        One other possibility is that you compiled under 2.0, and the server
        only has 1.1 installed ... or vice versa. This shouldn't give the
        error you see, though ....

        --

        ..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
        Delphi skills make .NET easy to learn In print, in stores.

        Comment

        Working...