Zum Inhalt springen

Stream not disposed (ARCH1104)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.resource.stream-not-disposed · Severity warning · Category resource

Streams that are not disposed fail to release file handles and memory. Always manage streams with using.

var stream = File.OpenRead(path);
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
using var stream = File.OpenRead(path);
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);

Wrap the stream in a using declaration so it is closed automatically at the end of scope and the handle is released.