我們ASP.NET C#Web應用程序在以下環境中使用Rare System.NullReferenceException顯示了以前填充的HttpContext.Current.Session [「courseNameAssociatedWithLoggedInUser」]?
- .NET框架4
- 的Silverlight 4/PivotViewer
- IIS 7級
- 的Windows 2008
- 的Visual Studio .NET 2010 IDE
- C#
- HTTPS(SSL)
我們的Silverlight 4/PivotViewer控件顯然嵌入在 ASP.NET頁面中。
在極少數情況下,我們得到「未將對象引用設置爲 實例的對象。錯誤圍繞承載我們 的Silverlight在我們的獨立的Windows 2008年4月/ PivotViewer模塊與IIS 7 服務器ASP.NET頁面導航時
此外,還有很多關於錯誤的非常奇怪的事情,首先,它在有些用戶計算機上只出現有時只出現在 通常只有當用戶使用訪問我們的ASP的計算機時纔會發生。 NET網頁應用程序第一次。
Mor一旦我們清除了瀏覽器緩存,在導航我們的 Silverlight 4/PivotViewer模塊的ASP.NET頁面時,錯誤不會發生 。
有關錯誤的另一個有趣的方面是,它是指 絕對路徑的錯誤堆棧跟蹤 我的本地開發計算機上時,它是在現實中部署到獨立的Windows 2008服務器 與IIS 7 That`s真奇怪,因爲在我部署到 帶有IIS 7的獨立Windows 2008服務器之前,我確保文件(如web.config)中的所有 配置參數都參考 獨立服務器環境。換句話說,我刪除了任何 引用與我的本地 開發計算機相關的配置參數值。
因此,我很困惑,爲什麼它在我的 本地開發計算機上引用了錯誤堆棧跟蹤中的絕對路徑。
如果我們必須告訴用戶,如果用戶在使用該站點時得到「對象引用 未設置爲對象實例」的錯誤體驗,而且它也會是不好的用戶體驗要清除 他/她的瀏覽器緩存,每次錯誤顯示出來
Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] PivotServer.SectionBasedRelatedModules.SectionBasedPerlsViewer.tailorConfigurationDetailsOfPageElementsToFallInLineWithTutorialSelection() in C:\VisualStudioWorkSpace\VisualCSharpProjects\PerlsPivot\PivotServer\SectionBasedRelatedModules\SectionBasedPerlsViewer.aspx.cs:160 PivotServer.SectionBasedRelatedModules.SectionBasedPerlsViewer.Page_Load(Object sender, EventArgs e) in C:\VisualStudioWorkSpace\VisualCSharpProjects\PerlsPivot\PivotServer\SectionBasedRelatedModules\SectionBasedPerlsViewer.aspx.cs:146 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24 System.Web.UI.Control.LoadRecursive() +70 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3063
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
我看着它包含下面的代碼行160:
String coursename = HttpContext.Current.Session["courseNameAssociatedWithLoggedInUser"].ToString();
顯然,這告訴我們,有否v在HttpContext.Current.Session中變量「courseNameAssociatedWithLoggedInUser」的變量。
但是,我在另一臺計算機上採取了相同的步驟,但一切順利。 而且,我相信,我在儘快給予一個值HttpContext.Current.Session [「courseNameAssociatedWithLoggedInUser」]作爲用戶登錄。
是否HttpContext.Current.Session [「courseNameAssociatedWithLoggedInUser」]會損壞因爲某些原因?如果是這樣,爲什麼,我們如何防止它?
我應該使用Page.Session而不是HttpContext.Current.Session?這會有幫助嗎?
中或在呼叫者/不變量某處代碼中的錯誤:'PivotServer.SectionBasedRelatedModules.SectionBasedPerlsViewer.tailorConfigurationDetailsOfPageElementsToFallInLineWithTutorialSelection()'。當然,開發人員將不得不隔離究竟在哪裏/是什麼罪魁禍首。我建議使用調試器。如果「清除緩存」似乎「解決問題」,這聽起來像是要調查的東西..也許一些不良的數據/不變量被存儲,或試圖恢復文化依賴的性質。 – 2013-03-18 17:36:10
幾乎所有'NullReferenceException'的情況都是一樣的。請參閱「[什麼是.NET中的NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)」的一些提示。 – 2013-03-18 17:40:59
你可以發佈異常網站的代碼嗎? SectionBasedPerlsViewer.aspx.cs - 其中有160行的方法? – StingyJack 2013-03-18 17:41:01