Skip to content

File.Exists throws an ArgumentException when empty string paths are used #810

Closed

Description

@masood-haloratech

Describe the bug
MockFileSystem throws an System.ArgumentException ("The path is not of a legal form") when a empty string is passed to the File.Exists() method.

System.IO.File.Exists(string.Empty) returns false.

To Reproduce
Steps to reproduce the behavior:

        [Test]
        public void MockFile_Exists_ShouldReturnFalseForEmptyString()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            // Act
            var result = fileSystem.File.Exists(string.Empty);

            // Assert
            Assert.IsFalse(result);
        }

Expected behavior
fileSystem.File.Exists() should return false and behave like System.IO.File.Exists()

Activity

  1. fgreinacher commented on Feb 10, 2022

    @fgreinacher
    Contributor

    Thanks for reporting!

    Seems we don't respect https://docs.microsoft.com/en-us/dotnet/api/system.io.file.exists?view=net-6.0#remarks.

    PR welcome 😀

  2. added
    state: ready to pickIssues that are ready for being worked on
    and removed on Feb 10, 2022
  3. github-actions commented on Feb 17, 2022

    @github-actions

    This is addressed in release v16.1.11.

  4. added a commit that references this issue on Nov 1, 2024
    3b8ecbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions