Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA2000 false positives with DisposeAsync #3113

Closed
manchas opened this issue Dec 16, 2019 · 1 comment
Closed

CA2000 false positives with DisposeAsync #3113

manchas opened this issue Dec 16, 2019 · 1 comment

Comments

@manchas
Copy link

manchas commented Dec 16, 2019

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

@mavasani
Copy link
Contributor

Duplicate of #3042

@mavasani mavasani marked this as a duplicate of #3042 Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants