Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a web application, and tested it locally. Everything worked fine so it was deployed to the hosting server. After a few weeks some of the users started to experience the "Object reference not set to an instance of an object" error. This is currently happening only in the chrome browser(on other browsers the application starts normally for them), and also if they use the incognito mode in chrome the application is opening normally.

I can't debug the problem because the application is working fine for me(and most other users) in chrome.

Here is the whole error message, unfortunately i didn't get the line in code where the error is, even though i used <customerrors mode="Off"> in the web.config

C#
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.]
   INAWebAppTest.SiteMaster.Page_Load(Object sender, EventArgs e) +884
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Control.LoadRecursive() +145
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772


I don't know if this can be because of a newer version of application being deployed on the server, in combination with the users cookies?

If so, can You please advise what i could try to correct this issue. I can't ask all of the users to clean up their browser history and cookies, there are too many of them, and it wouldn't solve this issue if it happened again in the future.

Here is the code from the site master:

C#
    public partial class SiteLogin : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request.Cookies["userInfo"] != null)
            {
                Response.Cookies.Set(Request.Cookies["userInfo"]);
                Response.Cookies["userInfo"]["lastVisit"] = DateTime.Now.ToString();
                Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(7);
                if (Server.HtmlEncode(Request.Cookies["userInfo"]["userName"]) == null)
                {
                    Response.Redirect("~/Account/login.aspx");
                }
                if (Server.HtmlEncode(Request.Cookies["userInfo"]["role"]).Equals("3"))
                        Response.Redirect("~/Form/Progress.aspx");                 
                if (Server.HtmlEncode(Request.Cookies["userInfo"]["role"]).Equals("2"))
                        Response.Redirect("~/CForm/CHome.aspx");
                if (Server.HtmlEncode(Request.Cookies["userInfo"]["role"]).Equals("1"))
                        Response.Redirect("~/AForm/AHome.aspx");



            }
        }
    }
}

Here is the code from global.asax page:
C#
        protected void Session_Start(object sender, EventArgs e)
    {
 string sessionId;
        if (Session.SessionID!=null)
            sessionId = Session.SessionID;
        else
        {
            SmtpClient client = new SmtpClient();
            client.Port = xxx;
            client.Host = "xxx.xxx.xxx.xxx";
            client.EnableSsl = false;
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("");

            MailMessage mm = new MailMessage();
            mm.From = new MailAddress("xxx", "xxx");
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            mm.Subject = "Null object";
            mm.IsBodyHtml = true;
            mm.To.Add("xxx");
            string body = "null";
            mm.Body = body;
            try
            {
                client.Send(mm);

            }
            catch
            {

            }
}

In the first version of the application the global.asax was empty, but there were some problems with session being flushed, so I googled and found that the solution is this line of code:

C#
string sessionId = Session.SessionID;


This fixed that issue, but since some users were having the problem mentioned in this subject, i added some code around so that i get a message if the session variable isn't found. I never received this mail, so i don't think the problem is there.

Thank You for the help!
Posted
Comments
Rob Philpott 12-Feb-15 5:26am    
ASP.NET not my thing, but wouldn't you want a return statement after Response.Redirect?
anujshaarma 13-Feb-15 6:57am    
It's better you check which OS he is using like windows XP, 2008 and it's 32bit OS or 64bit OS.
Also which chrome version he is using 38 / 39. Also, check the same info of your system also, then compare the same, this will give you a clear picture to troubleshoot the issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900