Topic | Value |
---|---|
Id | IDISP011 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | ReturnValueAnalyzer |
Don't return disposed instance.
In the below example the FileStream
is disposed and not usable
public FileStream M(string fileName)
{
using var stream = File.OpenRead(fileName);
return stream;
}
Don't dispose an instance that is returned. Caller is responsible for disposing.
public FileStream M(string fileName)
{
return File.OpenRead(fileName);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP011 // Don't return disposed instance
Code violating the rule here
#pragma warning restore IDISP011 // Don't return disposed instance
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP011 // Don't return disposed instance
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP011:Don't return disposed instance",
Justification = "Reason...")]