473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Session & Casting & Generic, how??

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<Messagemessages = 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
Apr 15 '07 #1
2 5150
Jeff wrote:
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<Messagemessages = 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"];

--
Göran Andersson
_____
http://www.guffa.com
Apr 15 '07 #2
This blog could help:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
or here for a 2.0 version

http://www.webforumz.com/dotnet-fram...ssing-data.htm

"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
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<Messagemessages = 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


Apr 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: | last post by:
I ask something relative later but the answer make me cry ;-) If we duplicate the browser window (both in IE / Mozilla), both of 2 browser windows use the same session!!! This produces many...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
0
by: Rajesh Abraham | last post by:
I am new to Asp world and I have a doubt as follows. I have a class called objTranslator, which I declare and initiate global.asax as follows. Session_Start csTranslator.objTranslator...
13
by: dee | last post by:
Hi My code complies the following line: Session("passed") = 1 but puts wiggly error line under the second Session("passed") in the following expression: Session("passed") = Session("passed") +...
22
by: Adam Clauss | last post by:
OK, I have class A defined as follows: class A { A(Queue<B> queue) { ... } } Now, I then have a subclass of both classes A and B. The subclass of A (SubA), more specifically is passed a...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
1
by: Eric | last post by:
Let's say I have a base class that implements IComparable<baseClass>. Really it could be any interface but I'm picking that one for the sake of discussion. In this class, equality and comparisons...
2
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. (Session variable is guaranteed to have been assigned) protected override void OnPreInit(EventArgs e){ if...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.