我有以下代码段
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)
答案 0 :(得分:1)
直接从XslCompiledTransform.Load Method注释部分复制:
在调试模式下编译的XSLT与XSLT之间存在差异 在发布模式下编译。在某些情况下,编译的样式表 调试模式不会在Load期间抛出错误,但稍后会失败 在变换期间。在发布模式下编译的相同样式表将 加载期间失败。这种行为的一个例子是当一个变量 不是将节点集类型分配给表达式中的a 节点集是必需的。