IDISP001 Potential Issue
fossbrandon opened this issue · 0 comments
I've run into a situation where I believe the analyzer is giving me a false positive IDISP001
error. Here is the code broken into pieces to try and demonstrate what is happening:
public static async Task<bool> VmExistsAsync(string identifier)
{
var command = Cli.Wrap(Constants.VirtualBoxCli)
.WithArguments($"showvminfo \"{identifier}\"");
using var commandTask = command.ExecuteAsync();
var result = await commandTask ;
return result.ExitCode is 0;
}
The analyzer throws an IDISP001
error on the var result = await task
line claiming that a dispose is created. The code for commandTask
of type CommandTask
can be found in the CliWrap GitHub CommandTask Code and is a disposable object. However, when I await the task I get a result of type CommandResult
which is not disposable making me think that the analyzer is incorrect. The CommandResult
code can be found in the CliWrap GitHub CommandResult Code.
When I go ahead and apply the IDISP001
suggestion, I get a compiler error CS1674.
Also, if I remove the using
statement in the line using var commandTask = command.ExecuteAsync()
I do not get a disposable warning when I believe I should since CommandTask
is disposable. I feel like this and the situation above could be related in how the analyzer is interpreting this setup.
I'm hoping someone can help me understand the situation some more and either correct my understanding of how this should behave or fix potential errors in the analyzer. Thanks!