Fork me on GitHub
TypeName DisposablesShouldCallSuppressFinalizeAnalyzer
Check Id CC0029
Category Naming
Severity Warning

Cause

Classes implementing IDisposable should call the GC.SuppressFinalize method in their finalize method to avoid any finalizer from being called.
This rule should be followed even if the class doesn’t have a finalizer as a derived class could have one.

Example

public class MyType : System.IDisposable
{
	public void Dispose()
	{
		var x = 123;
	}
}

Code fix

A code fix will be presented to you that will transform the code:

public class MyType : System.IDisposable
{
	public void Dispose()
	{
		var x = 123;
		GC.SuppressFinalize(this);
	}
}

Code fix

Related rules

None

See also

TBD