Skip to content

UriComponents.Path documentation implies LocalPath is always returned, but this is only true for file:// URIs #13039

Description

@MichalLabuda

Type of issue

Missing information

Description

UriComponents.Path documentation implies LocalPath is always returned, but this is only true for file:// URIs`

The documentation for UriComponents.Path currently says:

Path: The LocalPath data.

This wording suggests (by omission) that LocalPath is always returned, regardless of URI scheme.
However, this is only true for file:// URIs.
For all non-file URIs (e.g., http://, https://, ftp://), UriComponents.Path returns the URL path, not LocalPath.

This leads to incorrect expectations about path formatting, especially regarding Windows-style backslashes.

Below is a minimal reproducible example demonstrating the actual behavior.

Reproduction Code

var http = new Uri("https://example.com/a/b/c.txt");
var file = new Uri("file://server/share/c.txt");

Console.WriteLine(http.GetComponents(UriComponents.Path, UriFormat.Unescaped));
Console.WriteLine(http.LocalPath);

Console.WriteLine(file.GetComponents(UriComponents.Path, UriFormat.Unescaped));
Console.WriteLine(file.LocalPath);

// The example displays the following output:
// a/b/c.txt
// /a/b/c.txt
// share/c.txt
// \\server\share\c.txt

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.uricomponents?view=net-10.0

Content source URL

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

Document Version Independent Id

3d232e61-f2cd-8a85-f974-beb7ecade43c

Platform Id

be57ca08-cf67-4666-bdce-208a89903395

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions