Long path support fails with Unicode characters even with LongPathsEnabled=1 in .NET on Windows
Description
Even after enabling LongPathsEnabled in the Windows registry (set to 1 and system rebooted), .NET applications still fail to handle file paths that exceed the 260-character MAX_PATH limit and contain Unicode characters (Thai, Japanese, Russian, Greek, etc.).
Actual Behavior
- File operations throw
PathTooLongExceptionorDirectoryNotFoundException - Drag-and-drop of such paths throws
HRESULT: 0x8007007A(The data area passed to a system call is too small) - Explorer.exe automatically redirects to default folders when path is too long
- .NET file APIs do not properly handle the
\\?\prefix for long path bypass Environment - Windows 10/11 (latest version)
- .NET 6/7/8 (all versions affected)
- Reproduced in PCL 2(plain craft launcher)(a minecraft launcher) (C# .NET application) consistently
Reproduction Steps
- Enable long path support in Windows:
- Open
regeditas administrator - Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem - Set
LongPathsEnabledDWORD value to1 - Reboot the system
- Open
- Create a test path longer than 260 characters with mixed Unicode characters: C:\test\ภาษาไทยカタカナРусскийΑλφαβητα\1\2\3\4\5\6\7\8\9\0\1\2\3\4\5\6\7\8\9\0\test.txt
- Use .NET
File.ReadAllText()orDirectory.GetFiles()to access the path - Observe the exception/error
Expected Behavior
.NET should fully support long paths with Unicode characters when
LongPathsEnabledis enabled, consistent with native Windows system behavior. The same path works correctly in PowerShell and native Win32 applications, confirming it's a .NET-specific bug.
Expected behavior
.NET should fully support long paths with Unicode characters when LongPathsEnabled is enabled, consistent with native Windows system behavior.
The same path works correctly in PowerShell and native Win32 applications, confirming it's a .NET-specific bug.
Actual behavior
- File operations throw
PathTooLongExceptionorDirectoryNotFoundExceptionwhen accessing paths longer than 260 characters with Unicode characters - Drag-and-drop of such paths throws
HRESULT: 0x8007007A(The data area passed to a system call is too small) - Explorer.exe automatically redirects to default folders when path is too long, even with
LongPathsEnabledenabled - .NET file APIs do not properly handle the
\\?\prefix for long path bypass
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Tagging subscribers to this area: @dotnet/area-system-io See info in area-owners.md if you want to be subscribed.
Is the required longPathAware element in the application manifest? https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#application-manifest-updates-to-declare-long-path-capability
Is the required
longPathAwareelement in the application manifest? https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#application-manifest-updates-to-declare-long-path-capability
Thanks for the hint!
PCL2 (Plain Craft Launcher 2) is a typical C# .NET application distributed as a single EXE file without an external manifest file.
Currently, PCL2 does not have the <longPathAware>true</longPathAware> declaration in its manifest. Even though the system-wide LongPathsEnabled is set to 1, .NET APIs fail to handle Unicode paths longer than 260 chars due to the lack of this manifest setting.
If this fix is applied to PCL2, the progress jumping bug during import should be completely resolved.
@JeremyKuhne could you please take a look and use your long paths expertise?