You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NET-3165 Fix S3971 FP: Support IAsyncLifetime (xUnit v3) #9777
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);
}
}
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.
pavel-mikula-sonarsource commented on Feb 10, 2026
Activity
pavel-mikula-sonarsource commentedon Feb 9, 2026
Hi @dnnr,
Thank you for reporting this case. I confirm it as False Positive.
[-]Fix S3971 FP: Support IAsyncLifetime (xUnit v3)[/-][+]NET-3165 Fix S3971 FP: Support IAsyncLifetime (xUnit v3)[/+]github-actions commentedon Feb 9, 2026
Internal ticket NET-3165
pavel-mikula-sonarsource commentedon Feb 9, 2026
@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?
dnnr commentedon Feb 10, 2026
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.
pavel-mikula-sonarsource commentedon Feb 10, 2026
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.