You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like there are quite a lot of issues relate to CA2000, not sure if this one is reported, and if the root cause is the same. But here is another repro, I guess. Func is necessary, and the line of code inside is also necessary, delete neither the warning is gone.
foreach (var i in Enumerable.Range(0, 10))
{
using var reader = new StreamReader(string.Empty); // <-- CA2000 reported here
Func(reader);
}
static void Func(TextReader param)
{
using var reader = new StreamReader(string.Empty);
}
Steps To Reproduce
See above.
Expected behavior
No CA2000 warning.
Actual behavior
Program.cs(3,21): warning CA2000: Use recommended dispose pattern to ensure that object created by 'new StreamReader(string.Empty)' is disposed on all paths. If possible, wrap the creation within a 'using' statement or a 'using' declaration. Otherwise, use a try-finally pattern, with a dedicated local variable declared before the try region and an unconditional Dispose invocation on non-null value in the 'finally' region, say 'x?.Dispose()'. If the object is explicitly disposed within the try region or the dispose ownership is transfered to another object or method, assign 'null' to the local variable just after such an operation to prevent double dispose in 'finally'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2000)
Additional context
The text was updated successfully, but these errors were encountered:
Analyzer
Diagnostic ID: CA2000:
Dispose objects before losing scope
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 9.0.101
Describe the bug
Looks like there are quite a lot of issues relate to CA2000, not sure if this one is reported, and if the root cause is the same. But here is another repro, I guess.
Func
is necessary, and the line of code inside is also necessary, delete neither the warning is gone.Steps To Reproduce
See above.
Expected behavior
No CA2000 warning.
Actual behavior
Additional context
The text was updated successfully, but these errors were encountered: