views:

236

answers:

1

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)
A: 

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.

ileon
Yeah that's the only other thing I could think of, but it's a hard-coded string. I've edited my question to provide the declaration of `StaticStringProperty`. `StaticIntProperty` is an int so will never be null.
Andy Shellam
Perhaps you could give the stack trace to take a look.
ileon
I've posted the stack-trace. I can't see anything particularly useful in there but feel free to take a look.
Andy Shellam