Topic | Value |
---|---|
Id | IDISP004 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | CreationAnalyzer |
Don't ignore created IDisposable.
In the following code the file is opened but not closed.
public sealed class Foo
{
public Foo()
{
File.OpenRead("file.txt");
}
}
Assign the value to a field or property or use it in a using if it is a temporary value.
In the following code the file is opened but not closed.
public sealed class Foo
{
public Foo()
{
using(var file = File.OpenRead("file.txt"))
{
...
}
}
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP004 // Don't ignore created IDisposable
Code violating the rule here
#pragma warning restore IDISP004 // Don't ignore created IDisposable
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP004 // Don't ignore created IDisposable
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP004:Don't ignore created IDisposable",
Justification = "Reason...")]