Hi all,
I'm having a very strange problem. The third line in the following code
gives me a null reference exception when used in an ASP.Net web page. The
code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean
Get
If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception
occurs here**
Return CType(Session("SDSVarsSetup"), Boolean)
Else
Return Nothing
End If
End Get
Set(ByVal Value As Boolean)
If Not IsNothing(HttpContext.Current) Then
Session("SDSVarsSetup") = Value
End If
End Set
End Property
I don't understand how a null reference exception can occur when I'm
checking for a null reference condition. I have checked the code at a
different stage of the page life cycle (i.e. Load) and the values are present
and work fine. It appears to be a problem with the Handle Postback Events
stage. Does anyone know why this might happen?
Thank you very much. 5 4472
Do you have EnableSessionState="false" in either the @ Page directive
or in the web.config, perhaps?
--
Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 13:11:06 -0800, "Matt"
<Ma**@discussions.microsoft.com> wrote: Hi all,
I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean Get If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception occurs here** Return CType(Session("SDSVarsSetup"), Boolean) Else Return Nothing End If End Get Set(ByVal Value As Boolean) If Not IsNothing(HttpContext.Current) Then Session("SDSVarsSetup") = Value End If End Set End Property
I don't understand how a null reference exception can occur when I'm checking for a null reference condition. I have checked the code at a different stage of the page life cycle (i.e. Load) and the values are present and work fine. It appears to be a problem with the Handle Postback Events stage. Does anyone know why this might happen?
Thank you very much.
Do you have EnableSessionState="false" in either the @ Page directive
or in the web.config, perhaps?
--
Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 13:11:06 -0800, "Matt"
<Ma**@discussions.microsoft.com> wrote: Hi all,
I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean Get If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception occurs here** Return CType(Session("SDSVarsSetup"), Boolean) Else Return Nothing End If End Get Set(ByVal Value As Boolean) If Not IsNothing(HttpContext.Current) Then Session("SDSVarsSetup") = Value End If End Set End Property
I don't understand how a null reference exception can occur when I'm checking for a null reference condition. I have checked the code at a different stage of the page life cycle (i.e. Load) and the values are present and work fine. It appears to be a problem with the Handle Postback Events stage. Does anyone know why this might happen?
Thank you very much.
Scott,
Thanks for your idea.
I thought of that, but the session information is available at other stages
in the page lifecycle, so Session is working just not at the Handle Postback
events stage. But to explicitly answer your question, yes, sessionstate is
enabled via the webconfig, and I don't explicity set it anywhere else.
Is there a way in code to check to see if session is enabled?
Also something to note, I have the trace on and can see the session variable
that I'm looking for in the trace output. Hope someone can help. I need to
get this fixed ASAP.
Thank you very much!
"Scott Allen" wrote: Do you have EnableSessionState="false" in either the @ Page directive or in the web.config, perhaps?
-- Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 13:11:06 -0800, "Matt" <Ma**@discussions.microsoft.com> wrote:
Hi all,
I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean Get If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception occurs here** Return CType(Session("SDSVarsSetup"), Boolean) Else Return Nothing End If End Get Set(ByVal Value As Boolean) If Not IsNothing(HttpContext.Current) Then Session("SDSVarsSetup") = Value End If End Set End Property
I don't understand how a null reference exception can occur when I'm checking for a null reference condition. I have checked the code at a different stage of the page life cycle (i.e. Load) and the values are present and work fine. It appears to be a problem with the Handle Postback Events stage. Does anyone know why this might happen?
Thank you very much.
Scott,
Thanks for your idea.
I thought of that, but the session information is available at other stages
in the page lifecycle, so Session is working just not at the Handle Postback
events stage. But to explicitly answer your question, yes, sessionstate is
enabled via the webconfig, and I don't explicity set it anywhere else.
Is there a way in code to check to see if session is enabled?
Also something to note, I have the trace on and can see the session variable
that I'm looking for in the trace output. Hope someone can help. I need to
get this fixed ASAP.
Thank you very much!
"Scott Allen" wrote: Do you have EnableSessionState="false" in either the @ Page directive or in the web.config, perhaps?
-- Scott http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 13:11:06 -0800, "Matt" <Ma**@discussions.microsoft.com> wrote:
Hi all,
I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean Get If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception occurs here** Return CType(Session("SDSVarsSetup"), Boolean) Else Return Nothing End If End Get Set(ByVal Value As Boolean) If Not IsNothing(HttpContext.Current) Then Session("SDSVarsSetup") = Value End If End Set End Property
I don't understand how a null reference exception can occur when I'm checking for a null reference condition. I have checked the code at a different stage of the page life cycle (i.e. Load) and the values are present and work fine. It appears to be a problem with the Handle Postback Events stage. Does anyone know why this might happen?
Thank you very much.
Ok, for some reason (unclear to me) when I changed the code to use
System.Web.HttpContext.Current.Session("VarName")
instead of
Session("VarName")
it fixed all of the problems. Can anyone explain this to me? I would
appreciate it.
Thanks,
Matt
"Matt" wrote: Hi all,
I'm having a very strange problem. The third line in the following code gives me a null reference exception when used in an ASP.Net web page. The code is called on the click of a button.
Public Overridable Property SDSVarsSetup() As Boolean Get If Not IsNothing(Session("SDSVarsSetup")) Then ' <-- **Exception occurs here** Return CType(Session("SDSVarsSetup"), Boolean) Else Return Nothing End If End Get Set(ByVal Value As Boolean) If Not IsNothing(HttpContext.Current) Then Session("SDSVarsSetup") = Value End If End Set End Property
I don't understand how a null reference exception can occur when I'm checking for a null reference condition. I have checked the code at a different stage of the page life cycle (i.e. Load) and the values are present and work fine. It appears to be a problem with the Handle Postback Events stage. Does anyone know why this might happen?
Thank you very much. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shannon |
last post by:
I am having a very stange issue happen to my web application. I am
trying to develop a simple shopping cart. The code works perfectly
when I run the application under http://localhost/myapp. ...
|
by: vasu devan via DotNetMonster.com |
last post by:
Hi,
I am two config section with same config section handler like follow.
<section name="Myformatters"
type="MyFramework.Configuration.FileHandlers.MyConfigFileHandler,
MyFramework"/>
<section...
|
by: Matt |
last post by:
Hi all,
I'm having a very strange problem. The third line in the following code
gives me a null reference exception when used in an ASP.Net web page. The
code is called on the click of a...
|
by: ankur seth via DotNetMonster.com |
last post by:
Getting error Null Reference exception when a procedure is called in vb.net
..Why does it occur and how to resolve it.
---
ANkur
--
Message posted via http://www.dotnetmonster.com
|
by: A_StClaire_ |
last post by:
hi,
I have a singleton class called 'Evaluation' which is a utility class
used to determine the strength of a poker hand. two members of
'Evaluation' are highCard and lowCard, two objects of...
| |
by: webbsk |
last post by:
I keep getting an exception when I call the DataAdapter Update method.
I have been trying to figure out what is causing the null reference
exception for this code for what seems like forever:
...
|
by: Simon Rigby |
last post by:
Hi folks,
A bizarre problem I am having.
I have a treeview which is bound to an XmlDataSource. The
XMLDataSource.Data property is set to the result of a function that
generates an XML...
|
by: Wayne Brantley |
last post by:
If you expose a public property of a usercontrol that accesses an object on
the user control it will give a null reference exception when you wrap that
in an update panel.
Others are having the...
|
by: labby |
last post by:
Hi,
I've application to capture video of image, grab the still image and process it. It runs well until I put loop to regrab and the still images many times automatically.. and the error happened....
|
by: pinman |
last post by:
hi i'm recieveing something called a null reference exception whenever i try to run my code. i am testing for a null value and if it is null i carry out some action, if false i recursively call the...
|
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,...
| |
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |