Error-- Specified cast is not valid

Discussion in 'ASP .Net' started by Justin, Dec 3, 2003.

  1. Justin

    Justin Guest

    Greetings all,

    I'm receiving this error when I attempt to pull data, in
    the form of an ArrayList out of a Session.

    ArrayList al = new ArrayList();
    al = (ArrayList)Session["myArrayList"]; // error here

    How can this cast be invalid, when the session data IS an
    ArrayList??

    What's going on here, but more importantly how do I fix
    this?

    Also note that the same code has worked in the past.

    Thanks,
    Justin
    Justin, Dec 3, 2003
    #1
    1. Advertising

  2. Anything you grab out of the Session has to be put in there first. Check to
    see whether it exists before referncing it. Example:

    ArrayList al
    if (Session["myArrayList"] != null)
    al = (ArrayList)Session["myArrayList"];

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Justin" <> wrote in message
    news:0aa701c3b9af$2850dfb0$...
    > Greetings all,
    >
    > I'm receiving this error when I attempt to pull data, in
    > the form of an ArrayList out of a Session.
    >
    > ArrayList al = new ArrayList();
    > al = (ArrayList)Session["myArrayList"]; // error here
    >
    > How can this cast be invalid, when the session data IS an
    > ArrayList??
    >
    > What's going on here, but more importantly how do I fix
    > this?
    >
    > Also note that the same code has worked in the past.
    >
    > Thanks,
    > Justin
    Kevin Spencer, Dec 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew
    Replies:
    0
    Views:
    665
    Andrew
    Aug 12, 2003
  2. Stefan Landgraf

    Re: 'Specified Cast Is Not Valid' Error!

    Stefan Landgraf, Aug 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Stefan Landgraf
    Aug 19, 2003
  3. Miguel Angel Dinelli
    Replies:
    1
    Views:
    446
    Chris Jackson
    Nov 13, 2003
  4. sviau
    Replies:
    3
    Views:
    4,763
    Steven Cheng[MSFT]
    Feb 17, 2004
  5. Alan Silver
    Replies:
    5
    Views:
    2,587
    Kevin Spencer
    Feb 15, 2005
Loading...

Share This Page