我们在 ASP.NET Web 应用程序中得到随机 System.NullReferenceException。我们正在使用 inproc 会话状态。堆栈跟踪:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at System.Web.SessionState.HttpSessionStateContainer.Remove(String name)
at System.Web.UI.SessionPageStatePersister.Save()
at System.Web.UI.Page.SaveAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
问题似乎来自我们已经像这样覆盖的 Page.PageStatePersister 属性。
protected override PageStatePersister PageStatePersister {
get {
return new SessionPageStatePersister(Page);
}
}
Reflector 显示 SessionPageStatePersister 在内部调用了 Session.Remove。
当直接在 Page 上调用 Session.Remove 时,我们会得到类似的随机 NullReferenceException。相关堆栈跟踪:
---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at System.Web.SessionState.HttpSessionStateContainer.Remove(String name)
at System.Web.SessionState.HttpSessionState.Remove(String name)
at PERH.WebFramework.Bases.PageBase.OnPreInit(EventArgs e) in
任何想法,什么可能导致这些异常?
环境:
IIS6、Windows Server 2003 64 位、.net Framework 3.5