Skip to content

Stream.Read assumed to fill the buffer (CA2022)

Key dotnet.resource.inexact-stream-read · Severity warning · Category resource

Microsoft analyzer CA2022. Flags Stream.Read/ReadAsync whose return value is ignored. Read may return fewer bytes than asked for; the rest of the buffer is then stale data.

var buffer = new byte[length];
await stream.ReadAsync(buffer, ct);
var buffer = new byte[length];
await stream.ReadExactlyAsync(buffer, ct);