在.net 4.7中使用长路径时出错 [英] Error using long paths in .net 4.7
问题描述
我已将本地组策略编辑器中的启用Win32长路径
设置为已启用
,然后重新启动计算机。
I have set Enable Win32 Long Paths
in the Local Group Policy Editor to Enabled
and restarted the computer.
这是代码:
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\zzzzzzzzzzzz ...
System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Users...\Desktop\zzzzzzzzzz...
(实际上是一条奇怪的错误消息。)
(Which is actually a strange error message.)
app.config已经具有:
app.config already has:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
更多信息(可能不重要)
我尝试添加此帖子和其他地方(尽管注释中指出,使用.net 4.7时并不需要) code>配置:
I tried adding as mentioned in this post and elsewhere (though as pointed out in the comments it's not needed when using .net 4.7) in app.config under configuration
:
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
仍然是相同的错误。
如果我仅使用一个 zzzzzz ...
它将在桌面上无错误创建它。
If I only use one zzzzzz...
it creates it on the desktop with no error.
我正在使用VS2017 Windows10。我尝试使用Winforms和WPF。
I'm using VS2017, Windows 10. I tried Winforms and WPF.
推荐答案
周年更新(RS1)有一个错误,该错误使长路径可以工作没有清单。对于任何更新的窗口,必须将应用程序清单文件项添加到项目中。否则,它将不起作用。
The Anniversary Update (RS1) has a bug that allow long paths to work without the manifest. For any updated windows you must add the Application Manifest File item to your project. Otherwise it will not work.
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
这篇关于在.net 4.7中使用长路径时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!