在 C# asp.net 中加载 XSLT 时出错
Posted
技术标签:
【中文标题】在 C# asp.net 中加载 XSLT 时出错【英文标题】:Getting Error while loading the XSLT in C# asp.net 【发布时间】: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”都显示了调试信息 【参考方案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
【讨论】:
以上是关于在 C# asp.net 中加载 XSLT 时出错的主要内容,如果未能解决你的问题,请参考以下文章
在 ASP.NET 中加载页面时更改 <area> 的背景颜色 [重复]