sonar-dotnet
sonar-dotnet copied to clipboard
S2930 doesn't recognize IAsyncDisposable
Description
S2930 doesn't recognize Dispose() and DisposeAsync() calls made in DisposeAsync() method, resulting in false-positives:
Issue is similar to #3324
Repro steps
Analyze following code:
namespace IAsyncDisposableBug
{
public sealed class Test : IAsyncDisposable
{
private readonly FileStream stream;
public Test()
{
stream = new FileStream("C://some-path", FileMode.CreateNew);
}
public async ValueTask DisposeAsync()
{
await stream.DisposeAsync();
}
}
}
Expected behavior
S2930 should not be raised if Dispose/DisposeAsync is called in DisposeAsync() method from IAsyncDisposable
Actual behavior
S2930 is raised when Dispose/DisposeAsync is called in DisposeAsync() method from IAsyncDisposable
Known workarounds
None
Related information
- Visual Studio version: 17.2.6
- SonarLint for Visual Studio: 6.6.0.49766
- Operating System: Windows 10
Hello @wiciok, Thank you for the report. I confirm this is a false positive.
Dear @wiciok ! The fix for this issue will be available in the next release. Thank you for reporting it and helping us improve the analyzer.