ReSharper 2026.1 Help

Code inspection: Return of a variable captured by 'using' statement

This inspection reports returning a value that is declared in a using scope. The returned object will already be disposed when the caller receives it.

Example

using System.IO; Stream OpenStream(string path) { using var stream = File.OpenRead(path); return stream; }
using System.IO; Stream OpenStream(string path) { var stream = File.OpenRead(path); return stream; }
01 April 2026