Avatar of dgloveruk
dgloveruk
 asked on

Testing for nothing causing an error as if it were nothing

I have a routine that essentially assigned a class to a session property.
It is supposed to detect when no class has yet been created for this session and then do so.
It usually works fine but in certain situations that I can't recoginse it returns nothing and yet I cannot seem to test for that eventuality.
I could use a error catch but I would like to understand why testing if something is nothing can cause this error.  As you can see I test if the Current object is also nothing before accessing the session object.
I would appreciate any insights on how this can occur when I am literally trying to detect the error it raises.  
Thanks,
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bembi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

what if try use:

If HttpContext.Current.Session.Item("cUserSession") Is Nothing Then

Open in new window


instead?

How to: Read Values from Session State

https://docs.microsoft.com/en-us/previous-versions/aspnet/03sekbw5(v=vs.100)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes