Stream not disposed (ARCH1104)
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.
Incorrect
Section titled “Incorrect”var stream = File.OpenRead(path);var buffer = new byte[stream.Length];stream.Read(buffer, 0, buffer.Length);Correct
Section titled “Correct”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.