GC.SuppressFinalize is called with something other than this

tx0/csharp:suppress-finalize-other-objectdefaultwarningreliability/object-contractsdepth fastbug

What it finds

GC.SuppressFinalize(obj) removes the finalizer of obj. In a Dispose method that is meant to stop the object's own finalizer, passing another object leaves the own finalizer in place and may stop a finalizer that still had work to do. The rule reports calls inside a method named Dispose or DisposeAsync whose argument is not this.

From the rule's source, suppress_finalize_other_object.rs.

Example from the rule's tests
using System; class Owner : IDisposable{    private readonly object inner = new object();     public void Dispose()    {        GC.SuppressFinalize(inner);tx0 reports: GC.SuppressFinalize is given another object than this    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:suppress-finalize-other-object" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:suppress-finalize-other-object] reason="..."

tx0 explain tx0/csharp:suppress-finalize-other-object shows the same in the terminal. Found a false positive? Report it.