在 C# asp.net 中加载 XSLT 时出错

本文关键字:XSLT 出错 加载 asp net | 更新日期: 2023-09-27 18:31:57

>当我尝试加载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

任何人都可以帮助我解决这个问题吗?任何帮助将不胜感激。提前谢谢。

在 C# asp.net 中加载 XSLT 时出错

试试这个,看看它是否有区别。

   // 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