Topic | Value |
---|---|
Id | IDISP001 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | ArgumentAnalyzer |
AssignmentAnalyzer | |
LocalDeclarationAnalyzer |
When you create an instance of a type that implements IDisposable
you are responsible for disposing it.
This rule will warn even if you have an explicit dispose call and try finally.
The reason for not filtering out those cases is that using reads better.
The following example will leave the file open.
var reader = new StreamReader(fileName);
return reader.ReadLine();
using (var reader = new StreamReader(fileName))
{
return reader.ReadLine();
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP001 // Dispose created
Code violating the rule here
#pragma warning restore IDISP001 // Dispose created
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP001 // Dispose created
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP001:Dispose created",
Justification = "Reason...")]