|
| 1 | +--- |
| 2 | +title: ".NET 8 breaking change: Backslash mapping in Unix file paths" |
| 3 | +description: Learn about the .NET 8 breaking change in core .NET libraries where the CoreCLR native runtime no longer maps backslashes to forward slashes in file paths on Unix. |
| 4 | +ms.date: 01/30/2023 |
| 5 | +--- |
| 6 | +# Backslash mapping in Unix file paths |
| 7 | + |
| 8 | +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. |
| 9 | + |
| 10 | +## Previous behavior |
| 11 | + |
| 12 | +The native CoreCLR runtime automatically converted backslash (`\`) characters in file paths to forward slashes (`/`) on Unix. |
| 13 | + |
| 14 | +## New behavior |
| 15 | + |
| 16 | +The native CoreCLR runtime doesn't convert any file path characters on Unix. |
| 17 | + |
| 18 | +## Version introduced |
| 19 | + |
| 20 | +.NET 8 Preview 1 |
| 21 | + |
| 22 | +## Type of breaking change |
| 23 | + |
| 24 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 25 | + |
| 26 | +## Reason for change |
| 27 | + |
| 28 | +Without this change, .NET apps located in directories that contain backslash characters fail to start. |
| 29 | + |
| 30 | +## Recommended action |
| 31 | + |
| 32 | +- Use <xref:System.IO.Path.DirectorySeparatorChar?displayProperty=nameWithType> as a directory separator in your app instead of hardcoding it to `\` or `/`. |
| 33 | +- Use `/` as a directory separator on Unix in file paths that you pass to the `dotnet` host, hosting APIs, and `ilasm` and `ildasm` tools. |
| 34 | +- Use `/` as a directory separator on Unix in file paths in various `DOTNET_xxx` [environment variables](../../../tools/dotnet-environment-variables.md). |
| 35 | + |
| 36 | +## Affected APIs |
| 37 | + |
| 38 | +- Hosting APIs |
| 39 | +- <xref:System.Runtime.InteropServices.DllImportAttribute.Value?displayProperty=fullName> |
| 40 | +- <xref:System.Runtime.InteropServices.NativeLibrary.Load%2A?displayProperty=fullName> |
| 41 | +- <xref:System.Runtime.InteropServices.NativeLibrary.TryLoad%2A?displayProperty=fullName> |
| 42 | +- <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=fullName> |
| 43 | +- <xref:System.Reflection.Assembly.LoadFile%2A?displayProperty=fullName> |
| 44 | +- <xref:System.Reflection.Assembly.UnsafeLoadFrom(System.String)?displayProperty=fullName> |
| 45 | +- <xref:System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(System.String)?displayProperty=fullName> |
| 46 | +- <xref:System.Runtime.Loader.AssemblyLoadContext.LoadFromNativeImagePath(System.String,System.String)?displayProperty=fullName> |
| 47 | +- <xref:System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(System.String)?displayProperty=fullName> |
0 commit comments