c# - 给定的路径格式不支持 c#

标签 c# xml xslt

我在尝试使用 C# 执行 XSLT 转换时遇到此异常:

Exception: System.NotSupportedException: The given path's format is not supported.
   at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)    
   at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
   at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
   at System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt)
   at System.Xml.XPath.XPathDocument..ctor(String uri, XmlSpace space)
   at System.Xml.XPath.XPathDocument..ctor(String uri)
   at ConsoleApplication8.Program.TransformXML(String sXmlPath, String sXslPath)

当我尝试运行这段代码时

 void test()
 {
     var myXslTrans = new XslCompiledTransform();
     myXslTrans.Load(@"‪C:\Users\ahmed\Desktop\fewf\visio.xsl");
     myXslTrans.Transform(@"‪C:\Users\ahmed\Desktop\fewf\page1.xml", @"‪C:\Users\ahmed\Desktop\fewf\page.html"); 
 }

我尝试使用 Path.Combine(); 但给我相同的情况
我该如何解决这个问题?

最佳答案

不幸的是,从您的问题中并不清楚您正在使用 Silverlight(或者至少是某种以某种方式触发此方法的平台)。当我开始搜索 QuickDemand 时,发现它只在 SilverLight(或类似的?)环境中被调用,所以我考虑到这一点重写了我的答案。

at System.Security.Permissions.FileIOPermission.QuickDemand

这个错误是由this block of code in the reference source引起的.从那里可以看出,如果路径在第二个位置上方包含一个冒号,则认为它是无效的。

在上面的代码中没有显示,但由于这是引用源中唯一抛出此特定错误的地方,我将假设您拥有的真实代码(可能 XSLT 中的任何 xsl:include)在第二个位置以外的某个位置包含冒号。

无论哪种方式,如果这没有帮助,请转到异常屏幕并检查 NotSupportedException 并在调试窗口中取消选中“仅我的代码”并选中“启用 .NET 框架源步进”。这样,您可以在抛出错误的位置中断,并使用 IntelliSense 和调试窗口找出导致此错误的上下文(即实际路径)。

此外,根据我之前的帖子,如果这没有帮助:

  • 使用最少的 XSLT 尝试您的代码(这很重要!)
  • 运行该程序后,添加一个 xsl:include
  • 运行该程序后,添加一个文档(如果您使用它,则在设置中启用它)
  • 一旦你开始运行......好吧,你明白了

关于c# - 给定的路径格式不支持 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428975/

相关文章:

c# - Datagrid 在调整大小时变得模糊

c# - 我想了解更多有关 LinkedList<T> 的信息

.net - 如何在 BindingSource.Filter 之后获取 DataGridView 的可见行数?

java - Android 中的自定义字体 : java. lang.RuntimeException

xml - Active Directory - 强制执行额外的身份验证

当属性值不同时XSLT合并节点

c# - Entity Framework 和 DataContractSerializer

c# - 如何从 WPF 表单中删除边框/控制框?

xslt - 如何使用 xslt 1.0 删除特定匹配的元素

java - 使用Java的XSL转换: number format issue