Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

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

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.

I have an app that usually works but sometimes tosses this error. I _think i have it narrowed down to the first page hit after an IIS restart...since this is on a production server I can't try again until tonight.

Can anyone read / interprete the error output to shed any light on what's going wrong.

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.]
   compliance4.loginGW.Page_Load(Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750
0
juststeve
Asked:
juststeve
1 Solution
 
apb2Commented:
Do this happen when you load the page, or after an event is fired.

Could be a few things. I would start with the your controls. Are you referencing a control in you behind code that isn't on your page, Check the spelling of the controls ID field corresponds with your behind code controls as well.

have fun.

apb2
0
 
adatheladCommented:
This error means you are attempting to use a object that hasn't been instantiated and as such is a very general error as it could be anywhere.

As you say you think this happens after an IIS restart, perhaps you are storing an object in the session that is cleared out by the restart. Then the next time you attempt to use that session object, it will cause this exception as it's no longer there.
e.g.
Dim SessionObject As MyObject
SessionObject.PropertyName = "Test"
Session("Object") = SessionObject

-- NOW SESSION TIMES OUT/IIS RESTARTS SO Session("Object") NO LONGER EXISTS.

CType(Session("Object"), MyObject).PropertyName = "Something new"
-- THIS WILL CAUSE THIS ERROR YOU ARE RECEIVING.

You can get round this by checking if the object is there:
If Not Session("Object") Is Nothing Then
    CType(Session("Object"), MyObject).PropertyName = "Something new"
End If



0
 
noshi316Commented:
may be some where in code you didnt initialize any variables.....
this error commes
check your code...
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now