C#


ROSLYN.RELIABILITY.CA2000 : Dispose objects before losing scope (C#)

See Roslyn-Detected C# Warning Classes for more information.

Summary

If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead.

This check corresponds to Roslyn rule CA2000. For full rule details, see the Microsoft website: CA2000.

Properties

Class Name Dispose objects before losing scope (C#)
Significance reliability
Mnemonic ROSLYN.RELIABILITY.CA2000
Categories None
Availability Available for C# only.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Dispose objects before losing scope (C#)"

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.