Our ASP.NET C# web application is used in the following environment
- .NET Framework 4
- Silverlight 4 / PivotViewer
- IIS 7
- Windows 2008
- Visual Studio 2010 .NET IDE
- C#
- HTTPS ( SSL )
Our Silverlight 4 / PivotViewer controls are obviously embedded in ASP.NET pages.
In rare cases we get the "Object reference not set to an instance of an object. error when navigating around ASP.NET pages that host our Silverlight 4 / PivotViewer modules on our standalone Windows 2008 server with IIS 7.
Also, there is number of very odd things about the error. First, it occurs only sometimes on certain user computers. To elaborate, it usually only occurs when a the user uses a computer that accesses our ASP.NET web application for the first time.
Moreover, once we clear the browser cache the error does Not occur when navigating around ASP.NET pages that host our Silverlight 4 / PivotViewer modules.
Another interesting aspect about the error is that it refers to absolute path on my local development computer in the error stack trace when it is in reality deployed to the standalone Windows 2008 server with IIS 7. That`s really strange because before I deploy to the standalone Windows 2008 server with IIS 7, I ensure that all configuration parameters in files such as web.config refer to the standalone server environment. In other words, I remove any references to configuration parameter values associated with my local development computer.
Therefore, I am confused as to why it refers to absolute path on my local development computer in the error stack trace.
It would be bad experience for the user to get the "Object reference not set to an instance of an object.` while using the site. Also, it would be bad user experience if we have to tell the user to clear his/her browser cache everytime the error shows up.
Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] PivotServer.SectionBasedRelatedModules.SectionBasedPerlsViewer.tailorConfigurationDetailsOfPageElementsToFallInLineWithTutorialSelection() in C:\VisualStudioWorkSpace\VisualCSharpProjects\PerlsPivot\PivotServer\SectionBasedRelatedModules\SectionBasedPerlsViewer.aspx.cs:160 PivotServer.SectionBasedRelatedModules.SectionBasedPerlsViewer.Page_Load(Object sender, EventArgs e) in C:\VisualStudioWorkSpace\VisualCSharpProjects\PerlsPivot\PivotServer\SectionBasedRelatedModules\SectionBasedPerlsViewer.aspx.cs:146 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24 System.Web.UI.Control.LoadRecursive() +70 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3063
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I looked at line 160 which contains the following code:
String coursename = HttpContext.Current.Session["courseNameAssociatedWithLoggedInUser"].ToString();
Obviously, this tells us that there is no value for the variable "courseNameAssociatedWithLoggedInUser" in the HttpContext.Current.Session.
However, I took the same steps on another computer but it all ran smoothly. Also, I am sure that I am giving a value to the HttpContext.Current.Session["courseNameAssociatedWithLoggedInUser"] as soon as the user logs in.
Does the HttpContext.Current.Session["courseNameAssociatedWithLoggedInUser"] get corrupted for some reason? If so, why, and how do we prevent it?
Should I be using Page.Session instead of HttpContext.Current.Session? Would that help?