When reading C# NetworkStream (from stream-type TCP socket), BinaryReader.ReadChar occasionally throws exceptions System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)'
All buffers have their default sizes (none of them are manually set) and setting bigger buffer sizes does not affect the issue.
And what is completely discouraging:
The exception does not occur when using breakpoint and walking step-by-step through the line with
ReadCharcallThe exception does not occur if
ReadCharis preceded byThread.Sleep(1000)(but can still occur with smaller timeouts)The exception does not occur when using
BinaryReaderonFileStream, where all precise bytes of TCP-server's answer are stored.
So, what can be the time-related issue with buffering single characters from stream a socket?