On rare occasion I get the following error and stack trace when someone access one of my ASP.NET applications:
Error: Object reference not set to an instance of an object.
Stacktrace: at MyApp.MyDefaultPage.Page_Init(Object sender, EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
OK a few things here. MyApp.MyDefaultPage does not have a defined Page_Init of my own so there is no additional code (I understand the event still fires). Also there is no base class code which it would run through either in a Page_Init event, so I am at a loss from where this is occuring.
The only thing I could even gather is I have a Global.asax exception handler code in the Application_Error event, but the 1st thing I do before accessing any objects is make sure they are Not Nothing before trying to access (to prevent any errors).
Any clue as to what could cause this sporadically?
Are you using any of the Ajax controls?
If so make sure your scriptmanager tag is the first item after your form tag
also give a try to setting EnableEventValidation=”false” for the page.
It could be caused by user interaction with the page before the page is fully loaded.