Skip to content

Path.Combine, HasExtension, GetFileName docs still describe .NET Framework volume-separator (:) handling #13124

Description

@ForNeVeR

Type of issue

Outdated article

Description

Several docs related to System.IO.Path APIs describe special handling of the volume separator (:) that modern .NET removed in .NET Core 2.1.

Path.Combine: the remarks for Combine(string, string), Combine(string, string, string), Combine(string, string, string, string) and Combine(params string[]) say a separator is appended only if the preceding path "is not a drive reference (that is, "C:" or "D:")" and does not end in DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar. On .NET Core 2.1+ only DirectorySeparatorChar/AltDirectorySeparatorChar are checked, and no drive references:

Call .NET 10 .NET Framework 4.x
Path.Combine("C:", "foo") C:\foo C:foo
Path.Combine("C:", "foo", "bar") C:\foo\bar C:foo\bar
Path.Combine(new[] { "C:", "foo" }) C:\foo C:foo

The fixed-arity overloads changed in dotnet/coreclr#15579, and the params string[] overload in dotnet/coreclr#16447. Discussion in dotnet/runtime#27535 confirms that the change was intentional.

The same PR, dotnet/coreclr#16447, has adjusted behavior of several other APIs in a similar manner (removed special treatment of :), invalidating some other remarks:

  • HasExtension (both overloads): return value and remarks say the search stops at VolumeSeparatorChar. It no longer does: Path.HasExtension(@"C:\a.b:c") is true on .NET 10 and false on .NET Framework.
  • GetFileName (both overloads): says the result is empty when the path ends in a volume separator. Only a drive root counts now: Path.GetFileName(@"C:\file.txt:stream") returns file.txt:stream on .NET 10 and stream on .NET Framework; Path.GetFileName("foo:") returns foo: on .NET 10 and an empty string on .NET Framework. (The string overload's remarks already list only DirectorySeparatorChar/AltDirectorySeparatorChar, which contradicts its own return-value text.)

Proposal: describe the modern behavior (only DirectorySeparatorChar/AltDirectorySeparatorChar are treated as separators; a drive reference such as C: is still recognized at the start of a path, but not treated specifically by the affected APIs, e.g. Path.Combine). Add notes on the volume-separator behavior being specific .NET Framework only.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=net-10.0#system-io-path-combine(system-string-system-string)

Content source URL

https://github.com/dotnet/dotnet-api-docs-temp/blob/live/xml/System.IO/Path.xml

Document Version Independent Id

fe224bbb-0eec-28fe-93e4-80a25b795e62

Platform Id

3916d1a3-5b50-d6c3-65d1-d12ac54cc834

Article author

@dotnet-bot

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions