vs-threading icon indicating copy to clipboard operation
vs-threading copied to clipboard

VSTHRD200 reports DisposeAsyncCore

Open MartyIX opened this issue 3 years ago • 1 comments

Bug description

VSTHRD200 should (probably) not report a warning for DisposeAsyncCore method name as it is recommended here: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync#disposeasync-and-disposeasynccore

Repro steps

Code to reproduce the behavior.

/// <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() // <<<<<<< WARNING HERE
{
    this.log.Debug("*");

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

        this.disposedValue = true;
    }

    // ...

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

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
    await this.DisposeAsyncCore().ConfigureAwait(false);
    GC.SuppressFinalize(this);
}

Expected behavior

No warning.

Actual behavior

A warning is emitted.

MartyIX avatar Mar 15 '21 10:03 MartyIX

It appears there is still an open discussion on this. Once that concludes I can update the analyzer with the result.

sharwell avatar Mar 16 '21 19:03 sharwell

@sharwell I just ran into this warning, too. Is the naming of DisposeAsyncCore() still up for discussion? 🙂

Eli-Black-Work avatar Oct 17 '22 08:10 Eli-Black-Work

.NET SDK analyzers have the same issue: https://github.com/dotnet/roslyn-analyzers/issues/3909 (AFAIK).

MartyIX avatar Oct 17 '22 09:10 MartyIX

@MartyIX Thanks, I was curious if that was the case for the .NET SDK analyzers as well 🙂

Eli-Black-Work avatar Oct 18 '22 09:10 Eli-Black-Work