Error-- Specified cast is not valid

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
 
K

Kevin Spencer

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top