You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ShellStream.CanWrite should not be false when disposed #1621
The CanWrite property value should not change depending on the disposed state of the stream. This behavior is highly confusing and wasn't intended by the BCL authors. That property is supposed to inform users of whether the stream supports writing at all. It's expected that e.g. a Write() fails with NotSupportedException if CanWrite is false. Basically, this is meant to be false for read-only streams only. It also means, due to the fact that a session getting disconnected disposes the ShellStream (not great either), the property might suddenly be false, leading to an exception when constructing a StreamWriter around the ShellStream.
If a class derived from Stream does not support writing, a call to Write, BeginWrite, or WriteByte throws a NotSupportedException. In such cases, Flush is typically implemented as an empty method to ensure full compatibility with other Stream types since it's valid to flush a read-only stream.
Activity
Rob-Hague commentedon Mar 26, 2025
Hi, I found several examples in the BCL where the property values change. It does not seem so clear-cut:
https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetworkStream.cs#L383-L384
https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoStream.cs#L790-L791
https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Net.Security/src/System/Net/Security/NegotiateStream.cs#L265
https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs#L652
oold commentedon Mar 26, 2025
That does indeed contradict what the documentation says. I guess it's fine to do that. Even
FileStreamdoes that.