C#

C#

By DeepSource

Calling `Dispose` twice is UBCS-W1014

Bug risk

The Dispose method is used to dispose-off any resources that were acquired or used by an object. The using keyword automatically calls the Dispose method as soon as it goes out of scope, thereby eliminating the need for calling it manually. Since it may cause UB, it is recommended that you remove such explicit calls.

Examples

Bad Practice

using (var c = new Class())
{
    // ...
    c.Dispose();
}

Recommended

using (var c = new Class())
{
    // ...
}

Reference