Description
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
.
Quote from https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.canwrite?view=netframework-4.8.1#remarks:
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.