简体   繁体   English

XmlCompiledTransform.Load间歇性地引发NullReferenceException

[英]XmlCompiledTransform.Load throws a NullReferenceException intermittently

I have the following code snippet 我有以下代码片段

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);
}

It throws NullReferenceExcecption sometime and sometime it works on the same xslt file. 它有时会抛出NullReferenceExcecption,并且有时会在同一xslt文件上运行。

Could you please tell what is wrong with the above code? 您能告诉我上面代码有什么问题吗? Any help will be appreciated. 任何帮助将不胜感激。

Below is the stack trace 下面是堆栈跟踪

    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)

Directly copied from XslCompiledTransform.Load Method note section: 直接从XslCompiledTransform.Load方法注释部分复制:

There are differences between XSLT compiled in Debug mode and XSLT compiled in Release mode. 在调试模式下编译的XSLT与在发布模式下编译的XSLT之间存在差异。 In some situations, style sheets compiled in Debug mode will not throw errors during Load, but will later fail during Transform. 在某些情况下,在“调试”模式下编译的样式表在加载期间不会引发错误,但是稍后在“转换”期间将失败。 The same style sheet compiled in Release mode will fail during Load. 在“加载”期间,在“发布”模式下编译的相同样式表将失败。 An example of such behavior is when a variable that is not of a node-set type is assigned to an expression where a node-set is required. 这种行为的一个示例是将非节点集类型的变量分配给需要节点集的表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM