Skip to content

CA2213 does not recognize an IAsyncDisposable implementaton as sufficient. #4950

Closed

Description

Analyzer

Diagnostic ID: CA2013: Do not use ReferenceEquals with value types

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Describe the bug

CA2213 seemingly does not consider DisposeAsyncCore method.

/// <summary>State object for <see cref="RestClient"/>.</summary>
private readonly RestClientContext restContext; // <<<< CA2213: WARNING EMMITED HERE.

// ...

/// <summary>
/// Frees managed resources used by the object.
/// </summary>
/// <returns>A <see cref="ValueTask">task</see> that represents the asynchronous dispose operation.</returns>
protected virtual async ValueTask DisposeAsyncCore()
{
    this.log.Debug("*");

    lock (this.disposedValueLock)
    {
        if (this.disposedValue)
        {
            this.log.Debug("$<ALREADY_DISPOSED>");
            return;
        }

        this.disposedValue = true;
    }

    this.log.Debug("Dispose REST context.");
    this.restContext.Dispose(); // // This does not make the warning go away!

    this.log.Debug("$");
}

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
    // this.restContext.Dispose(); // THIS MAKES THE WARNING GO AWAY.
    await this.DisposeAsyncCore().ConfigureAwait(false);
    GC.SuppressFinalize(this);
}

Steps To Reproduce

Please see the source code above.

Expected behavior

No warning is emitted when this.restContext.Dispose(); is called in DisposeAsyncCore.

Actual behavior

A warning is emitted when this.restContext.Dispose(); is called in DisposeAsyncCore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designFalse_PositiveA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commenting

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions