XslCompiledTransform类的Load方法抛出StackOverflow异常

时间:2017-02-09 12:12:46

标签: c# .net xslt

我正在尝试构建我们公司的项目和

的加载方法
  

XslCompiledTransform抛出StackOverflow异常

并且它让我感到烦恼,因为五分钟之前,我能够构建并且现在没有更改模板或代码开始throw exceptions ...

if (context.Request.IsLocal)
{
    var cc = new XslCompiledTransform();
    using (var xmlReader = new XmlTextReader(context.Server.MapPath("/templates/xhtmlmain.xsl"))
        { DtdProcessing = DtdProcessing.Parse })
    {
        cc.Load(xmlReader);
    }
    return cc;
}

1 个答案:

答案 0 :(得分:1)

在我的情况下,我必须使用大于默认堆栈大小的线程,因为我们写得不好的模板无法重构。

这是代码:

 private static XslCompiledTransform LoadTransformations(HttpContext context, XslCompiledTransform cc)
    {

        using (var xmlReader = new XmlTextReader(context.Server.MapPath("/templates/xhtmlmain.xsl"))
        {
            DtdProcessing = DtdProcessing.Parse
        })
        {
            cc.Load(xmlReader);
        }
        return cc;
    }

    private static XslCompiledTransform CreateTransformation(HttpContext context)
    {
        var cc = new XslCompiledTransform();

        // Since our templates are most likely poorly written it takes
        // unusual amount of memory for a thread to handle the transformation
        // leaving the application throwing StackOverflow Exception.

        // This code creates different thread with 8MB stack size which actually succeeds in
        // transforming all the templates.

        // Creates custom thread and start it.  
        Thread t = new Thread(() => cc = GTHttpHandler.LoadTransformations(context, cc), 8 * 1024 * 1024);
        t.Start();

        // Ensure our transformation thread is finished before doing anything.
        t.Join();

        return cc;
    }