Skip to content

Path.GetInvalidPathChars() Does not Return the Same Character Set between .NET4.8 and .NET 6.0.1 on Windows #63383

Description

@kabua

Description

Path.GetInvalidPathChars() returns a different character set between .NET 4.8 and .NET 6.0-windows.

According to Path.GetInvalidPathChars Method Remarks documentation ...The full set of invalid characters can vary by file system. Okay, but running .NET4.8 vs .NET6.0 on the same machine using the same OS should return the same results since the file system has not changed, correct?

Reproduction Steps

Project file:

  <PropertyGroup>
    <TargetFrameworks>net48;net6.0-windows</TargetFrameworks>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

Test code:

var frameworkDescription = RuntimeInformation.FrameworkDescription;
var osDescription = RuntimeInformation.OSDescription;
var osArchitecture = RuntimeInformation.OSArchitecture;

var illegalPathChars = "[" + Path.GetInvalidPathChars().Join(null, "") + "]";

Expected behavior

.net 4.8 and .net 6.0 running on Windows should return the same character set.

Actual behavior

Running against .NET4.8 returned:

"[\"<>|\0\u0001\u0002\u0003\u0004\u0005\u0006\a\b\t\n\v\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f]"

Running against .NET 6.0.1 returned:

"[|\0\u0001\u0002\u0003\u0004\u0005\u0006\a\b\t\n\v\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f]"

Regression?

Yes.
.NET 6.0.1 is missing the following 3 characters: ", <, and >.

Known Workarounds

No.

Configuration

Used: Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.4
On: Microsoft Windows 10.0.19043, X64

Other information

We have been the process of porting our Framework from .NET 4.8 to .NET 6.0 on Windows and when we ran our unit tests, one of our unit tests failed due to the above issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions