奇怪的路径..Net 4.6.1 &4.6.2 for以0x85 char结尾的文件路径(windows 8)

本文关键字:路径 文件 结尾 char windows 0x85 Net for | 更新日期: 2023-09-27 18:13:38

我找不到这个奇怪路径的原因。.Net 4.6.1 &4.6.2 for以0x85 char结尾的文件路径(windows 8).

代码:

var _originalPath = @"D:'user'/web.config." + (char) 0x85;
string _fullPath = Path.GetFullPath(_originalPath);

使用4.6.1会正确返回:_fullPath = D:'user'web.config

然而,如果我切换到4.6.2,那么它变成:_fullPath = D:'user'web.config.

(请参阅额外依然! !):(

我错过了一些东西,但我不知道是什么。

在这方面有知识的人可以帮助解释/解决这个问题吗??

namespace ConsoleApplication1
{
  public class Program
  {
    internal static void Main(string[] args)
    {
        GetVersionFromRegistry();
        var _originalPath = @"D:'user'/web.config." + (char) 0x85;
        string _fullPath = Path.GetFullPath(_originalPath);
        Console.WriteLine(_fullPath);
        Console.ReadLine();
    }
  }
}

奇怪的路径..Net 4.6.1 &4.6.2 for以0x85 char结尾的文件路径(windows 8)

我无法重现这一点,但这种行为上的变化可能与。net 4.6.2中添加的对长文件名的支持有关。根据发布说明,你总是可以通过在app.config中输入以下内容来切换回以前的行为:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=true" />
  </runtime>
</configuration>