Click here to Skip to main content
12,951,983 members (61,861 online)
Rate this:
Please Sign up or sign in to vote.
See more:

i'm storing the DataTable information into Session . in the same page i'm calling that Session obj.
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 11-Oct-12 21:15pm
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.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.


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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100