Skip to content

Directory.Move throws invalid exception message #50833

@nmoreaud

Description

@nmoreaud

When destination directory is invalid, Directory.Move() throws an exception claiming that parts of source directory does not exist.

Snippet:

using System.IO;

try
{
    // cleanup
    Directory.Delete("dst", true);
} catch {}
Directory.CreateDirectory("src");
Directory.Move("src", "dst/dst"); // dst/dst is nested and doesn't exist ; move failure

Current error message:

Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/dev/projects/test/src'.
at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath)
at System.IO.Directory.Move(String sourceDirName, String destDirName)
at $.

$(String[] args) in /home/dev/projects/test/Program.cs:line 8

I think the exception message should be something like: System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/dev/projects/test/dst/dst'.

I guess the error comes from here: https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/mscorlib/system/io/directory.cs#L1266

Configuration

.Net 5.0.102 - Ubuntu 20.4 - x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOhelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions