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

Posted on 2006-04-27
Last Modified: 2008-02-01
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
Question by:juststeve
    LVL 6

    Expert Comment

    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.

    LVL 23

    Accepted Solution

    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.
    Dim SessionObject As MyObject
    SessionObject.PropertyName = "Test"
    Session("Object") = SessionObject


    CType(Session("Object"), MyObject).PropertyName = "Something new"

    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

    LVL 1

    Expert Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now