Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

i'm storing the DataTable information into Session . in the same page i'm calling that Session obj.
C#
gbds = ((DataTable)Session["datatable"]).Clone();

i have a data in my session object. sometimes it's working fine but sometimes its show the error " Object reference not set to an instance of an object ".
i know the session Default timeout is 20min, but my browser ideal time is just 1 or 2 min. In that also it's shows that error message. for that i run that application in sharepoint site but here also it's shows the same problem. What's the wrong in that can any one help me what's the problem on here.


Thankx in advance...
Posted
Comments
Zoltán Zörgő 12-Oct-12 3:18am    
How exactly are you putting your data in the session? Be aware, that if you put only a reference in it, there is no guarantee, that the object is hold for you.
Sergey Alexandrovich Kryukov 12-Oct-12 17:43pm    
Sure. I explained what happened and what exactly to do, please see my answer.
--SA
[no name] 12-Oct-12 3:22am    
k what's the solution for that

1 solution

This exception simply means that Session["datatable"] is null. You are trying to dereference this object by calling .Clone() with this instance, but it cannot be done as the instance is null; this is exactly what throws this exception. You did not add any value by the index "datatable", or misspelled it, something like that.

In general case, is some object is supposed to by non-null, make sure it is initialized (in case of sessions, it could be in a different page). Alternatively, check an object for null before dereferencing it, and do something else in case of null.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900