Skip to content

Question: Is .NET behavior proper in the presence of the \\?\ prefix? What does "\\?\." exactly mean? #39300

Closed
@ericwj

Description

@ericwj

Description

I know \\?\ means 'do not parse', but might I halfway misuse this repo for a Win32 question about this syntax and the behavior of .NET path API's with them?

Is it even valid to use \\?\. unless there is something to talk to that is called exactly that? Like a device or file/directory that has such a weird name? Or should it in fact refer to the current directory and direct API's to maintain the \\?\ prefix to support long paths?

Also, I just give one example where path math isn't being done because the \\?\ prefix is present (presumably). Should this be and remain this way?

private const string PWD = "<PWD>";
[Theory]
[InlineData(@"\\?\.", @"\\?\" + PWD)]
[InlineData(@"\\?\C:\Users\..", @"\\?\C:\")]
public void GetFullPath(string path, string expected) {
    if (expected is object) expected = expected.Replace(PWD, Environment.CurrentDirectory);
    var actual = Path.GetFullPath(path);
    Assert.Equal(expected, actual);
}

First result

  Message: 
    Assert.Equal() Failure
                  ↓ (pos 4)
    Expected: \\?\C:\Users\(...)\b.Tests\b···
    Actual:   \\?\.
                  ↑ (pos 4)

Second result

  Message: 
    Assert.Equal() Failure
                     ↓ (pos 7)
    Expected: \\?\C:\
    Actual:   \\?\C:\Users\..
                     ↑ (pos 7)

Configuration

Same on netcoreapp3.1 as on net5.0

> dotnet --list-sdks
3.1.301 [C:\Program Files\dotnet\sdk]
3.1.400-preview-015178 [C:\Program Files\dotnet\sdk]
5.0.100-preview.5.20279.10 [C:\Program Files\dotnet\sdk]

Regression?

Might be intended behavior.

Opinion

It could be useful to be able to do path math with \\?\ with an increasing number of machines able to use long paths since recent versions of Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions