CA2000
The .NET analyzer rule that warns when an IDisposable object may go out of scope without being disposed.
In more detail
A disposable object that is never disposed keeps its underlying resource open until the garbage collector eventually runs. Leaked files, sockets or connections can exhaust a service, which is why the course raises this rule to a warning.
Related terms
- IDisposable — The .NET interface with a single Dispose method, implemented by types that own something the garbage collector cannot clean up, such as a file, socket or database connection.
- Roslyn analyzer — A plug-in to the C# compiler that inspects code while you edit and build, and reports diagnostics about likely bugs, unsafe patterns or style.
- using declaration — A local variable declared with using, as in using var stream = File.OpenRead(path);, whose Dispose method runs automatically at the end of the enclosing scope.
Taught in
- Code Quality: .editorconfig and Roslyn Analyzers — Modern .NET Core, C# & Enterprise Microservices