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 fromasync 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.