Session & Casting & Generic, how??

J

Jeff

ASP.NET 2.0

In the business logic layer I've got the code (see CODE) below, this code
gives a compile error (see ERROR)

CODE:
List<Message> messages = null;
messages = HttpContext.Current.Session["inbox"];

ERROR:
Cannot implicitly convert type 'object' to
'System.Collections.Generic.List<BLL.Message>'. An explicit conversion
exists (are you missing a cast?)

I've tried these approaches for casting, but they fails:
messages = (Message)HttpContext.Current.Session["inbox"];
messages = List<Message>HttpContext.Current.Session["inbox"];

How should I do this cast?

Best Regards

Jeff
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jeff said:
ASP.NET 2.0

In the business logic layer I've got the code (see CODE) below, this code
gives a compile error (see ERROR)

CODE:
List<Message> messages = null;
messages = HttpContext.Current.Session["inbox"];

ERROR:
Cannot implicitly convert type 'object' to
'System.Collections.Generic.List<BLL.Message>'. An explicit conversion
exists (are you missing a cast?)

I've tried these approaches for casting, but they fails:
messages = (Message)HttpContext.Current.Session["inbox"];
messages = List<Message>HttpContext.Current.Session["inbox"];

How should I do this cast?

Like this:

messages = (List<Message>)HttpContext.Current.Session["inbox"];
 

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

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top