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)