Επεξεργασία

Κοινή χρήση μέσω


FileStream writes when pipe is closed

FileStream error handling on Windows has been updated to be consistent with NamedPipeServerStream, NamedPipeClientStream, AnonymousPipeServerStream, and AnonymousPipeClientStream.

Previous behavior

Previously, when writing to a FileStream that represented a closed or disconnected pipe, the underlying operating system error was ignored and the write was reported as successful. However, nothing was written to the pipe.

New behavior

Starting in .NET 8, when writing to a FileStream whose underlying pipe is closed or disconnected, the write fails and an IOException is thrown.

Version introduced

.NET 8 Preview 1

Type of breaking change

This change is a behavioral change.

Reason for change

This change was made to unify the handling of edge cases and avoid silent errors that are difficult to diagnose.

Close or disconnect the pipe after everything has been written.

Affected APIs