1

I'd like to completely eliminate the possibility that my project contains async void. If somebody attempts to write an async void method, there should be a build error or warning.

The compiler doesn't seem to complain on its own, and my attempts to find an analyzer that could do it have failed.

Is this possible?


Motivation:

  • We have an ASP.NET Core API project, where throwing an exception from a an async void controller method crashes the entire process (we can handle exceptions from async Task methods just fine).
  • Also, we have some async tests in an MSTest project, where forgetting to return Task could lead to some strange wonkiness during the test run.

We don't have any event handlers and don't need async void anywhere, so it's safest to simply forbid it.

Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167
  • 2
    This appears to do what you want: https://roslyn-analyzers.readthedocs.io/en/latest/analyzers-info/async/avoid-async-void-methods.html – Kirk Woll Mar 10 '23 at 14:13

0 Answers0