Skip to content

File.Create throws exception for relative file paths #401

Closed

Description

@Gav-Brown

Package Version

2.1.0.256

Repro steps

  1. Create MockFileSystem
  2. Create working directory
  3. Set working directory
  4. Call

using (var file = fileSystem.File.Create("File.txt")) { }

Expected behavior

File is created in current working directory (which does exist).

Actual behavior

Exception is thrown.
Could not find a part of the path 'File.txt'.

This worked in version 2.0.0.144. I suspect it is due to change for #278 an #286
which assumes an absolute file path rather than a relative one.

.NET Framework version handles both cases, as does

fileSystem.File.WriteAllText("File.txt", null);

Activity

  1. fgreinacher commented on Nov 15, 2018

    @fgreinacher
    Contributor

    Thanks for reporting this! Could you test if the problem also occurs in the latest prerelease version? #372 might already have fixed it.

  2. Gav-Brown commented on Nov 16, 2018

    @Gav-Brown
    Author

    Thanks. Alas it still throws in latest beta.

                string workingDirectory = @"C:\folder";
                string relativeFile = "file.txt";
                var fileSystem = new MockFileSystem();
    
                fileSystem.Directory.CreateDirectory(workingDirectory);
                fileSystem.Directory.SetCurrentDirectory(workingDirectory);
    
                // Throws.
                using(fileSystem.File.Create(relativeFile))
                {
                }
    
                // Works.
                fileSystem.File.WriteAllText(relativeFile, null);
    
  3. ThomasBarnekow commented on Nov 25, 2018

    @ThomasBarnekow

    This seems to be related to my issue #404.

    The funny thing is that issue 404 is related to something that is not found ;-)

  4. fgreinacher commented on Nov 28, 2018

    @fgreinacher
    Contributor

    @Gav-Brown The problem is fixed with ec1b673. Could you verify your use case with the prerelease version https://www.nuget.org/packages/System.IO.Abstractions/2.2.10-beta?

  5. Gav-Brown commented on Nov 29, 2018

    @Gav-Brown
    Author

    @fgreinacher Thanks. I've tested and can confirm this is now resolved.

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

    state: in workIssues that are currently worked ontype: 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