Skip to content

DirectoryInfo.CreateSubdirectory fails in .NET Core 2.1 when DirectoryInfo path ends in separator #26448

@daxian-dbw

Description

@daxian-dbw

Repro Steps:

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

Fail when building with netcoreapp2.1

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

</Project>
## version 2.1.300
> dotnet.exe run

Unhandled Exception: System.ArgumentException: The directory specified, 'blah', is not a subdirectory of 'C:\'.
Parameter name: path
   at System.IO.DirectoryInfo.CreateSubdirectory(String path)
   at dumpConsole.Program.Main(String[] args) in E:\arena\dotnetApp\test\dumpConsole\Program.cs:line 11

Work when building with netcoreapp2.0

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>
## version 2.1.300
> dotnet.exe run

## the folder "c:\blah" was created successfully.

This regression might be introduced by dotnet/corefx#27810

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions