Menu

Object reference not set to an instance of an

Help
2008-11-12
2013-04-11
  • Chris Nicel

    Chris Nicel - 2008-11-12

    Hi Andrew,

    I hate to be the bearer of bad news, but I'm getting a problem when I try to log in as a user. I am able to log in as admin no trouble. But the following message appears when I try to log in as a normal user immediatley after I press the log on button.

    Server Error in '/TimeRep' 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:

    Line 64:
    Line 65:             Page.Title = TXT_PAGETITLE;
    Line 66:             this.LblPageTitle.Text = string.Format("{0} {1}", TXT_PAGETITLE, ViewState["UserName"].ToString());
    Line 67:
    Line 68:             this.LblCompanyName.Text = Util.AttributeLoad("CompanyName", "Your Co");

    Source File: c:\Inetpub\wwwroot\TimeRep\Default.aspx.cs    Line: 66

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       _Default.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\TimeRep\Default.aspx.cs:66
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

    Many Thanks

    Chris Nicel

     
    • AndrewM

      AndrewM - 2008-11-12

      Hi Chris,
      I'm sorry to hear that you are having a problem. I'm at work presently but will try to get back to you this evening all being well.

      Regards,
      Andrew

       
    • AndrewM

      AndrewM - 2008-11-12

      Hi Chris,
      Sorry I couldn't answer earlier, however I have now had a look into this problem with a view to trying to recreate it.

      I installed the web site on a new client PC which has never seen TimeRep previously. In fact I only installed windows XP on the PC a few weeks ago and am still configuring my tools and development environment, and TimeRep happens to be the first web site it has ever seen! It is a virgin system.

      I then took the following actions:

      - Execute the 3 SQL scripts to create/configure the database.
      - Changed the web.config connection string.
      - Run the web site under Visual Studio 2005.

      I copied your process, first logging on as administrator and doing basic configuration. I set up a new user, then logged on as that user. As I had created the user with a weak password TimeRep forced me to change the user password - everything worked as expected.

      I logged out and back in again. No problems.

      Now to your issue. Line 66 of Default.aspx.cs (where it failed) suggests that the ViewState["UserName"] is null, which it should never be.

      If you can, could you put a debugger onto line 42 and single-step thru the Page_PreInit event from there? That's where ViewState["UserName"] gets set, so if there are going to be problems then that is where I would expect to see them appear.

      I'm afraid I have no magic solutions at the moment - I don't understand why that ViewState is null. If the Page_PreInit event worked then ViewState["UserName"] will definitely be set to something.

      Andrew

       

Log in to post a comment.

MongoDB Logo MongoDB