【问题标题】:.Net problem "Illegal characters in path.".Net 问题“路径中有非法字符”。
【发布时间】:2009-11-16 11:19:21
【问题描述】:

大家好,我不是 .net 开发人员,我来自 PHP、python 背景,我不知道如何处理。

尝试加载我们的网站之一时出现以下错误。请有人帮忙

[ArgumentException: Illegal characters in path.] System.IO.Path.CheckInvalidPathChars(String path) +7491109 System.IO.Path.GetFileName(String path) +19 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) +16 System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +77 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54 System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) +74 System.Threading.CompressedStack.runTryCode(Object userData) +70 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0 System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) +108 System.Xml.XmlTextReaderImpl.OpenUrl() +186 System.Xml.XmlTextReaderImpl.Read() +208 System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space) +217 System.Xml.XPath.XPathDocument..ctor(String uri, XmlSpace space) +116 System.Xml.XPath.XPathDocument..ctor(String uri) +6 OpenBay.Utils.XPathUtils.GetNodes(String xpathQuery, String xmlFile) +30 OpenBay.Wms.Controllers.SiteController.SetErrorPages(Site site) +21 OpenBay.Wms.Controllers.SiteController.GetSite(Uri uri, DirectoryInfo dir, String applicationName) +104 OpenBay.Wms.HttpModule.UrlProcessHttpModule.GetSiteParameters(HttpApplication app, RequestInfo info) +172 OpenBay.Wms.HttpModule.UrlProcessHttpModule.ProcessRequest(Object o, EventArgs args) +338 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

谢谢大家

【问题讨论】:

  • 如果您提供路径名会更有帮助,这样我们就可以查找不允许的字符。

标签: .net asp.net


【解决方案1】:

您的代码将调用System.IO.Path.CheckInvalidPathChars,它会依次检查以下内容:

  1. 双引号 (")

  2. 左尖括号 (

  3. 右尖括号 (>)

  4. 竖线(|)

对于小于 32 个十进制数的控制字符(空格)。

所以请确保您的路径不包含它们。

编辑: comment from Guy Lowe

我的问题是我在 c:\ 中未转义的 \ 使其 c:\ 修复了它

【讨论】:

  • 抱歉,我不确定 System.IO.Path.CheckInvalidPathChars 在哪里。我在哪里可以找到这个?
  • 您将在 System.IO.Path 命名空间中找到它,重要的是确保您的路径不包含上述字符。
  • 在使用Path类之前需要导入System.IO命名空间(不需要引用任何dll,因为它在mscorlib中声明)
  • @Ngu:路径是一个类,而不是命名空间。
  • CheckInvalidPathChars 是内部的,你不能从外部使用它(Nitpicker 的角落:没有反射)。
【解决方案2】:

很好的 Stacktrace,但无效的路径会更有帮助。

在我看来,提供给 OpenBay.Utils.XPathUtils.GetNodes(string, string) 的路径有一些无效参数。使用 System.IO.Path.CheckInvalidPathChars() 检查哪些字符无效并且可能包含在提供给上述方法的参数中。

【讨论】:

  • 抱歉,路径只是域根目录,我们已经很长时间没有更改网站上的任何内容,所以这出乎意料。 Use System.IO.Path.CheckInvalidPathChars() 位于哪里?
【解决方案3】:

请看这个链接,我使用的是 VS 2019: VS Test cases issue, NUnit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多