我无法找到在.Net 4.6.1和4.6.2之间以0x85 char(Windows 8)结尾的文件路径之间这种奇怪的Path.GetFullPath行为的原因。

码:

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.2中添加的对长文件名的支持有关。根据release notes,始终可以通过将以下内容放入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>

关于c# - .net 4.6.1和4.6.2之间奇怪的Path.GetFullPath行为不同,以0x85字符结尾的文件路径(Windows 8),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40128317/

10-17 02:11