Google Box
 News
  Tips Home :

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Doc TypeTips & Tricks
Email SettingMake Public
Email Addresssteve dot robinson at notes411 dot com
Keep informed?Yes
AuthorSteve C Robinson
Company NameNotes411
Category.NET, Web Application
Modified 06/09/2006 11:17:50
Subject Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

You are writing a web application and you decide to alter your global.asx file. When you try to debug this application you find you can an error in the code below.


protected
void Application_Start(Object sender, EventArgs e)
{

Application["AppplicationCount"] = 0;

Application["SessionCount"] = 0;

Application["AppplicationCount"] = (
int)Application["AppplicationCount"] + 1;
                     
}


protected
void Session_Start(Object sender, EventArgs e)
{

Application["SessCount"] = (
int)Application["SessCount"]+1;
Response.Write("Number of Applications: " +
Application["AppplicationCount"] + "< /br>");

Response.Write("Number of Sessions: " +
Application["SessCount"] + "< /br>");

}


Error:


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:

Line 32:                                   protected void Session_Start(Object sender, EventArgs e)
Line 33:                                   {

Line 34:                                                    Application["SessCount"] = (int)Application["SessCount"] + 1;

Line 35:                                                    Response.Write("Number of applications: " +
Line 36:                                                    Application["AppCount"] + "< /br>");






Solution:


The problem is that we are referencing an object that doesn't exist or is out of scope. The problem here was an Application variable SessionCount was spelt wrong in the
Session_Start method. It was Application["SessCount"] when it should have been Application["SessionCount"]


Add Response   ||  Add a Document



Responses to "Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.":

© 2003 notes411.com. All rights reserved. Disclaimer. site designed & developed by appsworks.com
Lotus Notes is a registered trademark of IBM. This site is not affiliated with IBM or Lotus.