A disposable class creates a resource in a field that none of its dispose methods mentions
What it finds
A class that implements IDisposable promises to release what it owns. A field initialized with new of a well-known disposable type, such as a stream, a timer or a CancellationTokenSource, that Dispose, DisposeAsync, Dispose(bool) and Close never mention, is not released with the object.
From the rule's source, disposable_field_not_disposed.rs.
using System;using System.Threading; class Worker : IDisposable{ private readonly CancellationTokenSource stop = new CancellationTokenSource(); private readonly SemaphoreSlim gate = new SemaphoreSlim(1);tx0 reports: gate holds a SemaphoreSlim that no dispose method releases public void Dispose() { stop.Cancel(); stop.Dispose(); }} 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:disposable-field-not-disposed" = "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:disposable-field-not-disposed] reason="..."tx0 explain tx0/csharp:disposable-field-not-disposed shows the same in the terminal. Found a false positive? Report it.