DotNetAnalyzers / IDisposableAnalyzers

Roslyn analyzers for IDisposable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IDISP013 "Await in using" is thrown for expression trees for async methods

ssg opened this issue · comments

The code below will throw IDISP013 when mocking up a class using Moq library:

public class O : IDisposable
{
  public async Task<int> SomeMethod()
  {
  ...
  }
}

private void mock()
{
  using var o = new O();
  var mock = createMock()
    .Setup(o => o.SomeMethod())
    .ReturnsAsync(5);
}

Setup() method receives an Expression<T>. So, the warning there feels superfluous. I don't think it has a feasible fix either. (Async lambda expressions can't be mapped to expression trees).