A class with a finalizer has a Dispose() that does not call GC.SuppressFinalize
What it finds
After Dispose has released everything, the finalizer has nothing left to do, but unless GC.SuppressFinalize(this) tells the runtime so, the object still waits in the finalization queue and survives one more collection. The rule reports a public parameterless Dispose in a class that declares a finalizer, when neither it nor any other member of the class calls GC.SuppressFinalize.
From the rule's source, finalizer_not_suppressed.rs.
using System; class Handle : IDisposable{ ~Handle() { Release(); } public void Dispose()tx0 reports: Dispose does not call GC.SuppressFinalize(this), though the class has a finalizer { Release(); } void Release() { }} class Safe : IDisposable{ ~Safe() { } public void Dispose() { GC.SuppressFinalize(this); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:finalizer-not-suppressed" = "warning"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:finalizer-not-suppressed] reason="..."tx0 explain tx0/csharp:finalizer-not-suppressed shows the same in the terminal. Found a false positive? Report it.