-
Notifications
You must be signed in to change notification settings - Fork 486
Closed
Closed
Copy link
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended designFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting
Milestone
Description
Analyzer
Diagnostic ID: CA2213: Disposable fields should be disposed
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: 6.0.302
Describe the bug
CA2213 doesn't recognize Dispose / DisposeAsync calls made in explicitly implemented IAsyncDisposable.DisposeAsync method, resulting in false-positive. This happens only when both IAsyncDisposable and IDisposable interfaces are implemented.
Steps To Reproduce
Run analyzers on following code sample:
namespace IAsyncDisposableBug
{
public sealed class Test : IAsyncDisposable, IDisposable
{
private readonly HttpClient client;
private readonly FileStream stream;
public Test()
{
client = new HttpClient();
stream = new FileStream("C://some-path", FileMode.CreateNew);
}
public void Dispose()
{
client.Dispose();
}
async ValueTask IAsyncDisposable.DisposeAsync()
{
await stream.DisposeAsync();
}
}
}
Expected behavior
Dispose/DisposeAsync calls are properly recognized regardless of how DisposeAsync() is implemented
Actual behavior
Dispose/DisposeAsync calls are not properly recognized when made from explicitly implemented IAsyncDisposable.DisposeAsync()
Metadata
Metadata
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended designFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting