我已经设定Enable Win32 Long Paths
in the 本地组策略编辑器 to Enabled
并重新启动计算机。
这是代码:
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
for (int i = 0; i < 10; i++)
path += "\\" + new string('z', 200);
Directory.CreateDirectory(path);
我收到错误:
System.IO.DirectoryNotFoundException: '找不到目录的一部分
路径 'C:\Users...\Desktop\zzzzzzzzzz...
(这实际上是一个奇怪的错误消息。)
app.config 已经有:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
更多信息(可能不重要)
我尝试添加中提到的这个帖子和其他地方(尽管正如评论中指出的那样,使用 .net 4.7 时不需要)在 app.config 下configuration
:
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
还是同样的错误。
如果我只使用一个zzzzzz...
它在桌面上创建它,没有错误。
我使用的是VS2017,Windows 10。我尝试过Winforms和WPF。
周年纪念更新 (RS1) 有一个错误,允许长路径在没有清单的情况下工作。对于任何更新的 Windows,您必须将应用程序清单文件项添加到您的项目中。否则它将无法工作。
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)