Topic | Value |
---|---|
Id | IDISP013 |
Severity | Warning |
Enabled | True |
Category | IDisposableAnalyzers.Correctness |
Code | ReturnValueAnalyzer |
Await in using.
public Task<string> M(string url)
{
using var client = new Client();
return client.GetStringAsync(url);
}
In the above code the client
is disposed when the method returns which may be before the task completes and depending on implementation this can lead to ObjectDisposedException
Use the fix to change the code to:
public async Task<string> M(string url)
{
using var client = new Client();
return await client.GetStringAsync(url);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable IDISP013 // Await in using
Code violating the rule here
#pragma warning restore IDISP013 // Await in using
Or put this at the top of the file to disable all instances.
#pragma warning disable IDISP013 // Await in using
[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness",
"IDISP013:Await in using",
Justification = "Reason...")]