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
CA2000 Call System.IDisposable.Dispose on object created by 'new StreamWriter(stream)' before all references to it are out of scope.
Repro steps
async Task Foo() { await using var sw= new StreamWriter("hello.txt"); await sw.WriteAsync("world").ConfigureAwait(false); }
Expected behavior
No violation.
Clearly the code is not calling Dispose(), but it is calling DisposeAsync() which should satisfy the condition of CA2000 for not throwing. With using instead of await using the violation goes away as expected, but using is not recommended as StreamWriter's Dispose BLOCKS the thread until the flush is done... A really bad practice
Actual behavior
Violation
The text was updated successfully, but these errors were encountered:
Analyzer package
Microsoft.CodeAnalysis.FxCopAnalyzers
Package Version
v2.9.8 (Latest)
Visual studio 2019 16.4.1
C# 8
Diagnostic ID
CA2000 Call System.IDisposable.Dispose on object created by 'new StreamWriter(stream)' before all references to it are out of scope.
Repro steps
async Task Foo() { await using var sw= new StreamWriter("hello.txt"); await sw.WriteAsync("world").ConfigureAwait(false); }
Expected behavior
No violation.
Clearly the code is not calling Dispose(), but it is calling DisposeAsync() which should satisfy the condition of CA2000 for not throwing. With using instead of await using the violation goes away as expected, but using is not recommended as StreamWriter's Dispose BLOCKS the thread until the flush is done... A really bad practice
Actual behavior
Violation
The text was updated successfully, but these errors were encountered: