2011-12-30 17 views
0

私は興味深い例外に遭遇しました。私のプロダクションサーバーの1つでは、次のような例外が発生することがあります。。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であることが示唆されます。奇妙なことは、この問題をローカルでテストすることも、テストサーバーでテストすることも決してできないということです。

少し背景があり、これがキーかもしれません... これは、XslCompiledTransform.Transform()に渡されるXmlDocumentをキャッシュするWebアプリケーション(.Net 3.5を実行しています)です。私たちのキャッシングは、分散型キャッシュサーバーを通じて処理されます。 XmlDocumentはシリアル化され、キャッシュされているので、特定のオブジェクトへの参照が存在し続けるべきではありません。これは、暗黙のXmlDocument - > DocumentXPathNavigatorが発生したとき、またはTransform()が実行されているときにどこかの参照が削除されたときに、何かが明示的に設定されないようにするものです。いずれにせよ、私は困惑している。

だから、私は私の質問があると思います:

  1. は誰が前にこれを見ていますか?
  2. それを引き起こしている可能性があること、またはそれを処理する方法を知っている人はいますか?

おかげ

EDIT:
さらに、このことを考えた後、理にかなっている唯一のことは、それが競合状態だということです。キャッシングアプライアンスは、アプリケーションがオブジェクトを使用している間、何らかの形でオブジェクトを期限切れにしています。

EDIT/EDIT:
.NET 3.5誰もが同じ例外を有している場合には、上記で参照されassembilies 2.0

+0

.NETバージョンはどれですか? –

+0

入力が間違っているようです。あなたはそれを検証しましたか? –

+0

スタックトレースに従うと、入力は実際にこの時点までに検証されます。それは、それが検証された時点と、この時点までになる時点との間で変更される可能性があります。 – John

答えて

0

あります。

この例外は、xmldocument.HasChildNodesがfalseまたはDocumentElementがnullの場合に発生します。ドキュメントに要素があることを確認すると、BEFOREが照会され、これが解決されます。

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) 

を、あなたと同じように、私たちは、XSL変換にXPathDocumentオブジェクトを渡したとXPathDocumentオブジェクトは、分散キャッシュから取得されていました。残念ながら、XPathDocumentは直列化できないため、分散キャッシュから取得した後は使用できません。問題を解決するには、XPathDocumentの代わりにXmlDocumentを使用し、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."); 
        } 
       } 
      } 
     }