Behavior changed about `filesystemInfo.Attributes` in .NET Core preview2/3 causes 2 tests to fail in `Get-ChildItem.Tests.ps1`
See original GitHub issueIn 2.0.0-preview1 .NET Core, filesystemInfo.Attributes raises an FileNotFoundException exception when the file is deleted or renamed during the enumration.
In 2.0.0-preview2/3 .NET Core, filesystemInfo.Attributes returns -1 without raising any exception.
This behavior change was by design – to align with the current behavior on Full .NET. For detailed information, please see https://github.com/dotnet/corefx/issues/20456.
This behavior change causes the following tests to fail in test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 (they will be marked as pending for now):
- “Should continue enumerating a directory when a contained item is deleted”
- “Should continue enumerating a directory when a contained item is renamed”
These 2 tests were added in PR #3806, which assumes that the FileNotFoundException will be thrown in case the file is deleted or renamed during enumeration. Since the behavior has changed in .NET Core, the fix needs to be revisited.
/cc @jeffbi
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (12 by maintainers)

Top Related StackOverflow Question
I quite agree. So long as our users understand that the file system is this dynamic, then this should be the expected behavior.
So my take is that we leave the cmdlet code as is, with no additional call to
Refresh(), and modify the tests to verify that the cmdlet does not show an error but instead retrieves the file information it can.Nothing needs to be done. This issue was not closed when merging #4200