2011-12-30 29 views
0

我遇到了一個有趣的異常。在我的一臺生產服務器上,偶爾我會得到以下例外。。DocumentXPathNavigator中的Net Null引用異常

System.NullReferenceException: Object reference not set to an instance of an object. 
    at System.Xml.DocumentXPathNavigator.get_NameTable() 
    at System.Xml.Xsl.Runtime.XmlQueryContext.get_DefaultNameTable() 
    at System.Xml.Xsl.Runtime.XmlQueryRuntime..ctor(XmlQueryStaticData data, Object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, XmlSequenceWriter seqWrt) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) 
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) 
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
    at sftControls.SearchListLandingPage.getHtml(IXPathNavigable document, String Xsl, String headerLinks) 

打開IL並查看每種方法都表明DocumentXPathNavigator => this.document爲null。奇怪的是,我絕不能在本地或我們的測試服務器上重複這個問題。

有一點背景,這可能是關鍵... 這是一個Web應用程序(運行.net 3.5),它緩存傳遞到XslCompiledTransform.Transform()的XmlDocument。我們的緩存服務通過分佈式緩存服務器進行。 XmlDocument被序列化和緩存,因此對特定對象的引用不應該繼續存在。這使我相信,在隱式XmlDocument - > DocumentXPathNavigator發生時,或者在Transform()運行時刪除某處的某個引用時,明確阻止設置此.document。無論哪種方式,我感到困惑。

所以,我想我的問題是:

  1. 有其他人見過這個?
  2. 有誰知道是什麼原因導致它或如何處理它?

感謝

編輯:
經過進一步思考這一點,那將是有意義的唯一的事情是,它是一個競爭狀態。高速緩存設備以某種方式在應用程序使用該對象時過期對象。

EDIT /編輯:
NET 3.5的,所述assembilies被上面提到的是2.0

+0

哪個.NET版本? – 2012-01-03 18:16:39

+0

聽起來像輸入不正確。你有沒有驗證它? – 2012-01-10 21:07:28

+0

如果您遵循堆棧跟蹤,輸入實際上在它到達此點之前進行驗證。它有可能在它被驗證時和它到達這一點之間發生變化。 – John 2012-02-02 17:57:06

回答

0

如果任何人有此相同的異常。

我們發現,當xmldocument.HasChildNodes爲false或DocumentElement爲null時發生此異常。驗證文檔是否有元素,之前查詢,解決此問題。

0

我經歷了XslCompiledTransform內一個非常類似的異常:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object. 
     at MS.Internal.Xml.Cache.XPathDocumentNavigator.get_NodeType() 
     at System.Xml.XPath.XPathNavigator.MoveToNonDescendant() 
     at System.Xml.Xsl.Runtime.DescendantMergeIterator.MoveNext(XPathNavigator input) 
     at <xsl:template name="SystemPartIncluded">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 PartNumber, XPathNavigator Description, IList`1 DescriptionOverride, IList`1 Quantity, IList`1 ExtendedPrice, String LabelWhiteSpace) 
     at <xsl:template name="compiler:generated"> (30)(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, XPathNavigator isBundledWithCanvas, XPathNavigator SoftwareExtendedPrice, XPathNavigator SoftwareUnitPrice, IList`1 PixelNet, IList`1 Revision_Date, IList`1 Catalyst) 
     at <xsl:template name="compiler:generated"> (45)(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, XPathNavigator SoftwareUnitPrice, XPathNavigator HardwareExtendedPrice, XPathNavigator HardwareUnitPrice, XPathNavigator PixelNetUnitPrice, XPathNavigator FusionUnitPrice) 
     at <xsl:template match="Quote">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last) 
     at <xsl:template match="/">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) 
     at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
     at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) 
     at MyApp.clsXML.XslTransformationToHtml(IQEntities DC, Int32 loggedOnUserID, IXPathNavigable input, String xslStylesheetFilePath, XsltArgumentList xslArgs, String XmlRepositoryVersion) in MyApp\App_Data\Static Classes\xml_routines.cs:line 510 
     at MyApp.clsQuote.RenderOneQuote(IQEntities DC, Int32 loggedOnUserID, Int32 quoteID, Boolean booPrintFormat, Boolean booDiscount_Prices, Boolean booIs_Super_Administrator, Boolean isHostRep, String strOrganization_Table_Caption, Boolean showBottomLineOnly) in MyApp\App_Data\Static Classes\quote_routines.cs:line 476 
     at MyApp.Pages.AJAX.BrowseQuotes.RenderSelectedQuote(Int32 quoteID) in MyApp\Pages\AJAX\BrowseQuotes.aspx.cs:line 66 
     at MyApp.Pages.AJAX.BrowseQuotes.ucQuotePicker1_OnQuoteSelectedEvent(Object sender, Int32 quoteID) in b:\DotNet\IQ\WinMetrics.IQ\Pages\AJAX\BrowseQuotes.aspx.cs:line 56 
     at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) 
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
     at System.Web.UI.Page.HandleError(Exception e) 
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
     at System.Web.UI.Page.ProcessRequest() 
     at System.Web.UI.Page.ProcessRequest(HttpContext context) 
     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

和你一樣,我們傳遞一個XPathDocument中的XSL轉換和XPathDocument中正在從分佈式緩存中檢索。不幸的是,XPathDocument不可序列化,因此在從分佈式緩存中檢索後不可用。我們通過使用XmlDocument而不是XPathDocument並使用SerializedXmlDocument對其進行序列化和反序列化來解決問題,如下所示:

 public static XmlDocument CachedXmlDoc 
     { 
      get 
      { 
       lock (_locker) 
       { 
        // maintain the Part XmlDocument in the distributed cache so that it can be reset from any production instance 
        SerializedXmlDocument serializedXmlDoc = Reliable.Application[Global.CACHED_XML_DOC] as SerializedXmlDocument; 
        XmlDocument cachedDoc = (serializedXmlDoc == null) ? null : serializedXmlDoc.XmlDocument; 
        if (cachedDoc == null) 
        { 
         cachedDoc = myController.CreateXmlDoc(); 
         Reliable.Application[Global.CACHED_XML_DOC] = new SerializedXmlDocument(cachedDoc); 
        } 
        return cachedDoc; 
       } 
      } 
      set 
      { 
       lock (_locker) 
       { 
        if (value == null) 
        { 
         Reliable.Application[Global.CACHED_XML_DOC] = null; 
        } 
        else 
        { 
         throw new Exception("Tried to set the cached XmlDocument to something other than null."); 
        } 
       } 
      } 
     }