Backslash mapping in Unix file paths
Backslash (\
) characters are valid in directory and file names on Unix. Starting in .NET 8, the native CoreCLR runtime no longer converts \
characters to directory separators—forward slashes (/
)—on Unix. This change enables .NET applications to be located on paths with names that contain backslash characters. It also allows the native runtime, dotnet
host, and the ilasm
and ildasm
tools to access files on paths that contain backslash characters.
Previous behavior
The native CoreCLR runtime automatically converted backslash (\
) characters in file paths to forward slashes (/
) on Unix.
New behavior
The native CoreCLR runtime doesn't convert any file path characters on Unix.
Version introduced
.NET 8 Preview 1
Type of breaking change
This change is a behavioral change.
Reason for change
Without this change, .NET apps located in directories that contain backslash characters fail to start.
Recommended action
- Use Path.DirectorySeparatorChar as a directory separator in your app instead of hardcoding it to
\
or/
. - Use
/
as a directory separator on Unix in file paths that you pass to thedotnet
host, hosting APIs, andilasm
andildasm
tools. - Use
/
as a directory separator on Unix in file paths in variousDOTNET_xxx
environment variables.
Affected APIs
- Hosting APIs
- System.Runtime.InteropServices.DllImportAttribute.Value
- System.Runtime.InteropServices.NativeLibrary.Load
- System.Runtime.InteropServices.NativeLibrary.TryLoad
- System.Reflection.Assembly.LoadFrom
- System.Reflection.Assembly.LoadFile
- System.Reflection.Assembly.UnsafeLoadFrom(String)
- System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String)
- System.Runtime.Loader.AssemblyLoadContext.LoadFromNativeImagePath(String, String)
- System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(String)
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho