Skip to content

DirectoryInfo.CreateSubdirectory fails when DirectoryInfo path is a root directory #116087

Description

@t4m45

Description

The same issue as #26448

Reproduction Steps

static void Main(string[] args)
{
    var d = new DirectoryInfo(@"C:\");
    d.CreateSubdirectory("bar");
}

Expected behavior

It creates the subdirectory

Actual behavior

System.ArgumentException: The directory specified, 'bar', is not a subdirectory of 'C:\'.
Parameter name: path
   at System.IO.DirectoryInfo.CreateSubdirectory(String path)
   ...

Regression?

In .NET Framework 4.8 it works fine

Known Workarounds

No response

Configuration

<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
<OutputType>Library</OutputType>
<Platforms>x86</Platforms>

Win 11 Pro 21H2 22631.2861 x64

Other information

This doesn't throw:

    static void Main(string[] args)
    {
        var d = new DirectoryInfo(@"C:\foo");
        d.CreateSubdirectory("bar");
    }

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions