我經歷了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.");
}
}
}
}
哪個.NET版本? – 2012-01-03 18:16:39
聽起來像輸入不正確。你有沒有驗證它? – 2012-01-10 21:07:28
如果您遵循堆棧跟蹤,輸入實際上在它到達此點之前進行驗證。它有可能在它被驗證時和它到達這一點之間發生變化。 – John 2012-02-02 17:57:06