Error-- Specified cast is not valid

  • Thread starter Thread starter Justin
  • Start date Start date
J

Justin

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
 
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.
 
Back
Top