Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi,
 
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 22:15pm
Comments
Zoltán Zörgő at 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 at 12-Oct-12 17:43pm
   
Sure. I explained what happened and what exactly to do, please see my answer.
--SA

1 solution

Rate this: bad
good
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.
 
—SA
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2014
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