1

I am having an exception which comes only in production not locally,

Error Message:

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)

And Stack Trace

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)

this error did not contain any line number of code or any specific information.

Parent Error message is as bellow:

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
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& completedSynchronously)

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, enter image description here

this error is reported on random pages, not every time.

Sohail Hameed
  • 978
  • 2
  • 9
  • 25

1 Answers1

2

old asp.net web form developers.

If you are trying to access a field or property of any server side control directly on client side and this object you are trying to access is null, you are likely to get this error and unfortunately the log is really limited. For example, in some cases, you have a control that is render and you have defined a property in aspx.cs side, in the getter it returns the object that is rendered. If the object is in a state where it is not rendered and / or null and you want to get the client side id of this object as <% = ThisObje.ClientID%> on the client side, you will get this error.

  • I'm on a team fortunate enough to be maintaining a Web Forms application in 2020, and we just got burned by this. In our aspx view HTML, we were outputting some HTML based on the Request like `userLanguage: '<%= Request.UserLanguages[0] %>'` in a script tag. In our Page_Load postback, we would Redirect the user to a different URL, but it looks like the page would still try to render, access the Request and blow up, presumably because it was destroyed due to the redirect. Now we set our properties in the Page_Load, keep logic out of your views, for the good of mankind! – Jacob McKay Oct 23 '20 at 16:57