我有以下代码片段
this.xslCompiledTransform = new XslCompiledTransform();
// initialize xsl transform
using (Stream xsltStream = currentAssembly.GetManifestResourceStream(this.TransformationFile))
using (XmlReader schemaReader = XmlReader.Create(xsltStream))
{
XsltSettings settings = new XsltSettings() { EnableScript = true };
this.xslCompiledTransform.Load(schemaReader, settings, null);
}
它有时会抛出 NullReferenceExcecption,有时它适用于同一个 xslt 文件。
你能告诉我上面的代码有什么问题吗?任何帮助将不胜感激。
下面是堆栈跟踪
Object reference not set to an instance of an object.
Stack Trace:
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitFor(QilIterator ndFor)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisitEnsureStack(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitXPathNodeValue(QilUnary ndVal)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisitEnsureStack(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvoke)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitTextCtor(QilUnary ndText, Boolean disableOutputEscaping)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitLoop(QilLoop ndLoop)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitElementCtor(QilBinary ndElem)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitElementCtor(QilBinary ndElem)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitSequence(QilList ndSeq)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitElementCtor(QilBinary ndElem)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.VisitConditional(QilTernary ndCond)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd, Type itemStorageType, Boolean isCached)
at System.Xml.Xsl.IlGen.XmlILVisitor.NestedVisit(QilNode nd)
at System.Xml.Xsl.IlGen.XmlILVisitor.Function(QilFunction ndFunc)
at System.Xml.Xsl.IlGen.XmlILVisitor.Visit(QilExpression qil, GenerateHelper helper, MethodInfo methRoot)
at System.Xml.Xsl.XmlILGenerator.Generate(QilExpression query, TypeBuilder typeBldr)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)