title: Null Reference Exception in ASP.NET website
body: <p>I am having an exception which comes only in production not locally, </p>
  
  <p><strong>Error Message:</strong></p>
  
  <blockquote>
    <p>System.NullReferenceException: Object reference not set to an instance of an  object. at
    ASP.modules_header_ascx.__Render__control1(HtmlTextWriter __w, Control
    parameterContainer) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at ASP.main_master.__Renderform1(HtmlTextWriter
    __w, Control parameterContainer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
    writer) at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter
    output) at
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter
    writer) at ASP.main_master.__Render__control1(HtmlTextWriter __w,
    Control parameterContainer) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter
    writer) at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p>
  </blockquote>
  
  <p><strong>And Stack Trace</strong></p>
  
  <blockquote>
    <p>at ASP.modules_header_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at ASP.main_master.__Renderform1(HtmlTextWriter
    __w, Control parameterContainer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
    writer) at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter
    output) at
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter
    writer) at ASP.main_master.__Render__control1(HtmlTextWriter __w,
    Control parameterContainer) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
    ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter
    writer) at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p>
  </blockquote>
  
  <p>this error did not contain any line number of code or any specific information.</p>
  
  <p>Parent Error message is as bellow:</p>
  
  <blockquote>
    <p>System.Web.HttpUnhandledException: Exception of type 
    'System.Web.HttpUnhandledException' was thrown. ---> 
    System.NullReferenceException: Object reference not set to an instance of an 
    object. at ASP.modules_header_ascx.__Render__control1(HtmlTextWriter __w, 
    Control parameterContainer) at 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, 
    ICollection >children) at ASP.main_master.__Renderform1(HtmlTextWriter Control 
    parameterContainer) at 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, 
    ICollection >children) at<br>
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter >writer) at 
    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) at 
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) at 
    ASP.main_master.__Render__control1(HtmlTextWriter __w, Control 
    parameterContainer) at 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, 
    ICollection >children) at 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter >writer, 
    ICollection children) at System.Web.UI.Page.Render(HtmlTextWriter >writer) at 
    System.Web.UI.Page.ProcessRequestMain(Boolean >includeStagesBeforeAsyncPoint, 
    Boolean includeStagesAfterAsyncPoint) --- End of >inner exception stack trace 
    --- at System.Web.UI.Page.HandleError(Exception e) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean 
    includeStagesBeforeAsyncPoint, >Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, 
    Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() 
    at System.Web.UI.Page.ProcessRequest(HttpContext context) at 
    ASP._404_page_aspx.ProcessRequest(HttpContext context) at 
    System.Web.HttpApplication.CallHandlerExecutionStep.System.
    Web.HttpApplication.>IExecutionStep.Execute() at 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; 
    completedSynchronously)</p>
  </blockquote>
  
  <p>This seems that some resource on page is missing and that call 404 page, but i have checked all the resources including images/css , one this i have noticed in network that some time few images on page return status cancel,
  <a href="https://i.stack.imgur.com/EY59M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EY59M.png" alt="enter image description here"></a></p>
  
  <p>this error is reported on random pages, not every time.</p>