开发者

ViewState is NULL in Page_Load but not postback

开发者 https://www.devze.com 2023-01-02 20:28 出处:网络
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.

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 开发者_StackOverflow中文版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.

0

精彩评论

暂无评论...
验证码 换一张
取 消