Skip to content

NET-3165 Fix S3971 FP: Support IAsyncLifetime (xUnit v3) #9777

Closed

Description

@dnnr

Description

Rule S3971 raises a false positive when calling GC.SuppressFinalize in a DisposeAsync method of a class that implements IAsyncLifetime from xUnit. The interface itself inherits IAsyncDisposable, so S3971 should accept this accordingly.

Unlike what I initially assumed, this doesn't seem to be a regression of #3639, but is caused by the intermediate interface. In the attached reproducer, Foo1 is the only case where S3971 is triggered.

Reproducer

class Foo1 : IAsyncLifetime
{
    public ValueTask DisposeAsync()
    {
        GC.SuppressFinalize(this); // <- S3971 complains here
        return ValueTask.CompletedTask;
    }

    public ValueTask InitializeAsync() => throw new NotImplementedException();
}

class Foo2 : IAsyncDisposable
{
    public ValueTask DisposeAsync()
    {
        GC.SuppressFinalize(this);
        return ValueTask.CompletedTask;
    }
}

class Foo3 : IDisposable
{
    public void Dispose()
    {
        GC.SuppressFinalize(this);
    }
}

Product and Version

SonarQube Server v2025.3.1

Activity

  1. pavel-mikula-sonarsource commented on Feb 9, 2026

    @pavel-mikula-sonarsource
    Contributor

    Hi @dnnr,

    Thank you for reporting this case. I confirm it as False Positive.

  2. changed the title [-]Fix S3971 FP: Support IAsyncLifetime (xUnit v3)[/-] [+]NET-3165 Fix S3971 FP: Support IAsyncLifetime (xUnit v3)[/+] on Feb 9, 2026
  3. github-actions commented on Feb 9, 2026

    @github-actions
    Contributor

    Internal ticket NET-3165

  4. pavel-mikula-sonarsource commented on Feb 9, 2026

    @pavel-mikula-sonarsource
    Contributor

    @dnnr, I have issue with reproducing the issue. I can't get it raised with the provided example.

    What's the target framework of your project, exact xunit package(s) that you reference and their versions?

  5. dnnr commented on Feb 10, 2026

    @dnnr
    Author

    My target framework is net8.0, and going by the packages lock file history, xUnit has been consistently at v3.2.0 since I've reported this.

    Unfortunately though, I cannot reproduce the FP anymore right now either. It might be due to the fact that the instance available to me has since been upgraded to v2025.6.1, but that's nothing more than a guess.

    I can understand if that means you'll have to close to issue for now. I can always reopen in case the problem resurfaces.

  6. pavel-mikula-sonarsource commented on Feb 10, 2026

    @pavel-mikula-sonarsource
    Contributor

    I don't see a change in that rule between those two versions, so I'm not sure why this doesn't reproduce anymore.

    Let's close this for now then. If you face the same issue again, feel free to reopen it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    False PositiveRule IS triggered when it shouldn't be.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions