Session & Casting & Generic, how??

  • Thread starter Thread starter Jeff
  • Start date Start date
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
 
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"];
 
Back
Top