简体   繁体   中英

ViewState is NULL in Page_Load but not postback

I've got a weird problem with a NullReferenceException on a high traffic website my company hosts. The exceptions are logged with full stack-traces but I am unable to reproduce it.

The exception occurs a couple of times a day, for different users, and it's a NullReferenceException thrown in the code block below:

protected void Page_Load(object sender, EventArgs e)
{
    ...

    if (!Page.IsPostBack)
    {
        ...
        this.ViewState[StaticClass.StaticStringProperty] = StaticClass.StaticIntProperty; // this is the line the exception occurs on
        ...
    }
}

The only place I can figure that a NullReferenceException would be thrown is if ViewState is NULL, but I've never known that and can't find any reason why this would be the case in a Page_Load that isn't a postback.

StaticStringProperty and StaticIntProperty are both initialised, static properties of StaticClass .

StaticStringProperty is defined as:

public const string StaticStringProperty = "IdFromClient";

Does anyone know how this could happen, or any other reason why a NullReferenceException would be thrown on the above line?

EDIT

As requested, the full stack-trace for the error is as follows. Line 54 is the line I've highlighted above.

at MyCompany.MyApplication.Appliance.Page_Load(Object sender, EventArgs e) in C:\Documents and  Settings\shellama\My Documents\MyApplication\Appliance.aspx.cs:line 54
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at MyCompany.MyApplication.PageBase.OnLoad(EventArgs e) in C:\Documents and Settings\shellama\My Documents\MyApplication\App_Code\PageBase.cs:line 58
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The only thing I can say about it (I had a similar situation recently) is that StaticClass.StaticStringProperty is NULL. But then again, you must have paid attention to this. I can't think of something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM