I\'ve just stumbled across a rather dangerous scenario while migrating an ASP.NET application to the async/await model.
The situation is that I made a method async:
You have a few options:
(? It assumes you post fixed all your async method with the Async keyword and the method call is in one line. If it is not true then do not use it (or add the missing validations to the expression).How to use Roslyn:
You can copy paste the previous solution. Create
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AsyncAwaitAnalyzer : DiagnosticAnalyzer
{ ...
}
class with logic, to detect the issue. And create
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AsyncAwaitCodeFixProvider)), Shared]
public class AsyncAwaitCodeFixProvider : CodeFixProvider
{ ...
}
class to provide fixing suggestions (add await) to the problem.
After a success build you will get your own .wsix package you can install it to your VS instance and after a VS restart is should start pick up the problems.