AsyncFixer 1.3.0

AsyncFixer helps developers in finding and correcting common async/await *misuses* (i.e., anti-patterns). AsyncFixer has been tested with thousands of open-source C# apps and successfully handles many corner cases. It currently detects 5 common kinds of async/await misuses and fixes 3 of them via program transformations.

Install-Package AsyncFixer -Version 1.3.0
dotnet add package AsyncFixer --version 1.3.0
<PackageReference Include="AsyncFixer" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AsyncFixer --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Here are async/await misuses (i.e., anti-patterns) that AsyncFixer can currently detect:

AsyncFixer01: Unnecessary async/await usage

There are some async methods where there is no need to use async/await keywords. It is important to detect this kind of misuse because adding the async modifier comes at a price. AsyncFixer automatically removes async/await keywords from those methods.

AsyncFixer02: Long-running or blocking operations inside an async method

Developers use some potentially long-running or blocking operations inside async methods even though there are corresponding asynchronous versions of these methods in .NET or third-party libraries. Some examples for such operations: Task.Wait(), Task.Result, StreamReader.ReadToEnd(), Thread.Sleep(), etc.

AsyncFixer automatically replaces those operations with their corresponding asynchronous operations and inserts an await expression. For instance, it converts Thread.Sleep(...) to await Task.Delay(...).

AsyncFixer03: Fire & forget async void methods

Some async methods are 'fire & forget', which return void. Unless a method is only called as an event handler, it must be awaitable. Otherwise, it is a code smell because it complicates control flow and makes error detection & correction difficult.

AsyncFixer automatically converts void to Task.

AsyncFixer04: Fire & forget async call inside a using block

Inside a using block, developers insert a fire & forget async call which uses a disposable object as a parameter or target object. It can cause potential exceptions or wrong results. For instance, developers create a Stream in the using statement, pass it to the asynchronous method, and then Stream will be implicitly disposed via a using block. When the asynchronous method comes around to writing to Stream, it is (very likely) already disposed and you will have an exception.

AsyncFixer05: Downcasting from a nested task to an outer task.

Downcasting from a nested task (Task<Task>) to a Task or awaiting a nested task is dangerous. There is no way to wait for and get the result of the child task.

Visual Studio Extension

If you want AsyncFixer to work just in the IDE and to work as an analyzer on every project you open in Visual Studio, please download the VSIX extension instead of this NuGet package from here:
AsyncFixer - Visual Studio plugin

Here are async/await misuses (i.e., anti-patterns) that AsyncFixer can currently detect:

AsyncFixer01: Unnecessary async/await usage

There are some async methods where there is no need to use async/await keywords. It is important to detect this kind of misuse because adding the async modifier comes at a price. AsyncFixer automatically removes async/await keywords from those methods.

AsyncFixer02: Long-running or blocking operations inside an async method

Developers use some potentially long-running or blocking operations inside async methods even though there are corresponding asynchronous versions of these methods in .NET or third-party libraries. Some examples for such operations: Task.Wait(), Task.Result, StreamReader.ReadToEnd(), Thread.Sleep(), etc.

AsyncFixer automatically replaces those operations with their corresponding asynchronous operations and inserts an await expression. For instance, it converts Thread.Sleep(...) to await Task.Delay(...).

AsyncFixer03: Fire & forget async void methods

Some async methods are 'fire & forget', which return void. Unless a method is only called as an event handler, it must be awaitable. Otherwise, it is a code smell because it complicates control flow and makes error detection & correction difficult.

AsyncFixer automatically converts void to Task.

AsyncFixer04: Fire & forget async call inside a using block

Inside a using block, developers insert a fire & forget async call which uses a disposable object as a parameter or target object. It can cause potential exceptions or wrong results. For instance, developers create a Stream in the using statement, pass it to the asynchronous method, and then Stream will be implicitly disposed via a using block. When the asynchronous method comes around to writing to Stream, it is (very likely) already disposed and you will have an exception.

AsyncFixer05: Downcasting from a nested task to an outer task.

Downcasting from a nested task (Task<Task>) to a Task or awaiting a nested task is dangerous. There is no way to wait for and get the result of the child task.

Visual Studio Extension

If you want AsyncFixer to work just in the IDE and to work as an analyzer on every project you open in Visual Studio, please download the VSIX extension instead of this NuGet package from here:
AsyncFixer - Visual Studio plugin

Release Notes

http://www.asyncfixer.com/CHANGELOG.md

Dependencies

This package has no dependencies.

GitHub repositories (16)

Showing the top 5 popular GitHub repositories that depend on AsyncFixer:

Repository Stars
MvvmCross/MvvmCross
The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
exceptionless/Exceptionless
Exceptionless server and jobs
FoundatioFx/Foundatio
Pluggable foundation blocks for building distributed apps.
Baseflow/LottieXamarin
Render After Effects animations natively on Android, iOS, MacOS and TvOS for Xamarin
rotorgames/Rg.Plugins.Popup
Xamarin Forms popup plugin

Version History

Version Downloads Last updated
1.3.0 13,949 5/27/2020
1.1.6 316,026 2/12/2018
1.1.5 49,414 2/21/2017
1.1.4 26,606 9/6/2016
1.1.3 50,582 3/23/2016
1.1.2 644 3/21/2016
1.1.1 712 3/19/2016
1.1.0 739 3/13/2016
1.0.0 1,286 7/29/2015
0.9.0 1,305 2/14/2015