[thelist] c# - Storing Objects in Session

Joshua Olson joshua at alphashop.net
Sun Jan 27 19:28:00 CST 2002


Hey all,

I'm trying something really silly by trying to learn some ASP.NET using c#.
I'm trying to store objects (from user defined classes) into the session.
They store fine (I think), but when I retrieve them the compiler says the
cast back to the original type is invalid.  Does anybody know how to solve
this?

Eg.

Foo f = new Foo();
Session["myvar"] = f;

When I try to retrieve it I use the code:

Foo f = (Foo)Session["myvar"]

I always get the following error:

System.InvalidCastException: Specified cast is not valid.

TIA,

-joshua




More information about the thelist mailing list