diff --git a/src/libraries/System.IO.FileSystem/tests/RandomAccess/GetLength.cs b/src/libraries/System.IO.FileSystem/tests/RandomAccess/GetLength.cs index 0bb405c487f02c..e4b482c675db41 100644 --- a/src/libraries/System.IO.FileSystem/tests/RandomAccess/GetLength.cs +++ b/src/libraries/System.IO.FileSystem/tests/RandomAccess/GetLength.cs @@ -41,8 +41,9 @@ public void ReturnsExactSizeForNonEmptyFiles(FileOptions options) [MemberData(nameof(GetSyncAsyncOptions))] public void ReturnsActualLengthForDevices(FileOptions options) { - // both File.Exists and Path.Exists return false when "\\?\PhysicalDrive0" exists - // that is why we just try and swallow the exception when it occurs + // Both File.Exists and Path.Exists return false when "\\?\PhysicalDrive0" exists + // that is why we just try and swallow the exception when it occurs. + // Exception can be also thrown when the file is in use (#73925). try { using (SafeFileHandle handle = File.OpenHandle(@"\\?\PhysicalDrive0", FileMode.Open, options: options)) @@ -51,7 +52,7 @@ public void ReturnsActualLengthForDevices(FileOptions options) Assert.True(length > 0); } } - catch (FileNotFoundException) { } + catch (IOException) { } } } }