Page_Load 中 ViewState 为 NULL,但回发中不为 NULL

发布于 2024-09-04 02:16:40 字数 1690 浏览 5 评论 0原文

我在我公司托管的高流量网站上遇到了 NullReferenceException 的奇怪问题。异常是用完整的堆栈跟踪记录的,但我无法重现它。

对于不同的用户,该异常每天会发生几次,并且它是在下面的代码块中抛出的 NullReferenceException:

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
        ...
    }
}

我能想到抛出 NullReferenceException 的唯一地方是如果 ViewState 为 NULL,但我从来不知道这一点,也找不到任何原因为什么在非回发的 Page_Load 中会出现这种情况。

StaticStringPropertyStaticIntProperty 都是 StaticClass 的初始化静态属性。

StaticStringProperty 定义为:

public const string StaticStringProperty = "IdFromClient";

有谁知道这是如何发生的,或者在上面的行中抛出 NullReferenceException 的任何其他原因?

编辑

根据要求,错误的完整堆栈跟踪如下。第 54 行是我在上面突出显示的行。

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃安静 2024-09-11 02:16:40

我唯一能说的(我最近也遇到过类似的情况)是 StaticClass.StaticStringProperty 是 NULL。不过话说回来,你一定也注意到了这一点。我想不出别的事了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文