【问题标题】:Getting Error while loading the XSLT in C# asp.net在 C# asp.net 中加载 XSLT 时出错
【发布时间】:2016-05-01 18:18:59
【问题描述】:

当我尝试加载 XSLT 时出现以下错误
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

string xmlFilePath = Path.Combine(GetAssemblyDirectory(), "TestResult.xml");
string xslFilePath = Path.Combine(GetAssemblyDirectory(), "SingleTableTestResult.xslt");
 strResultSummary = strResultSummary.Replace(ProjectPath, ProjectName);
File.WriteAllText(xmlFilePath, strResultSummary, System.Text.Encoding.UTF8);

//get the formatted HTML Report tranformed via xslt
string reportFileData = GenerateTestReport(xmlFilePath, xslFilePath);

//gets the path of the running assembly directory
private static string GetAssemblyDirectory()
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            DashboardBaseLogger.dashBoardlogger.WriteInfo("Directory location: " + Path.GetDirectoryName(path));
            return Path.GetDirectoryName(path);
        }

//Generates the test report
private string GenerateTestReport(string XMLFilePath, string XSLFilePath)
        {
            string reportFilePath = string.Empty;
            XslCompiledTransform transform = new XslCompiledTransform();
            transform.Load(XSLFilePath); //Exception here
            reportFilePath = Path.Combine(GetAssemblyDirectory(), "TestResult.html");
            transform.Transform(XMLFilePath, reportFilePath);
            return reportFilePath;          
        }

在此处获取异常transform.Load(XSLFilePath); //Getting an Exception here

谁能帮我解决这个问题? 任何帮助将不胜感激。 提前致谢。

【问题讨论】:

  • 您写的错误似乎是正常的调试消息,而不是运行时异常。您可以插入一个 try..catch 并编写完整的异常吗?
  • 在 Catch 块中,我收到“System.Threading.ThreadAbort”异常。
  • 有内部异常?
  • 所有异常属性如“Data, Source, Stacktrace, InnerException”都显示了调试信息

标签: c# asp.net xml xslt


【解决方案1】:

试试这个,看看有没有什么不同。

   // Create the XsltSettings object with script enabled.
    XsltSettings settings = new XsltSettings(false,true);//By default, the XslCompiledTransform class disables support for the XSLT document() function and embedded scripting. This is a way to bypass it.
    XslCompiledTransform transform = new XslCompiledTransform();
    transform.Load(XSLFilePath, settings, new XmlUrlResolver() ); //Exception here
    reportFilePath = Path.Combine(GetAssemblyDirectory(), "TestResult.html");
    transform.Transform(XMLFilePath, reportFilePath);
    return reportFilePath;  

更多信息在这里。 https://msdn.microsoft.com/en-us/library/66f54faw%28v=vs.110%29.aspx

【讨论】:

    猜你喜欢
    • 2017-09-06
    • 2014-05-24
    • 2016-09-07
    • 2013-05-18
    • 1970-01-01
    • 2013-03-04
    • 2011-06-27
    • 1970-01-01
    • 2012-07-23
    相关资源
    最近更新 更多