Lindhart.Analyser.MissingAwaitWarning 2.1.0-beta

This is a prerelease version of Lindhart.Analyser.MissingAwaitWarning.
Install-Package Lindhart.Analyser.MissingAwaitWarning -Version 2.1.0-beta
dotnet add package Lindhart.Analyser.MissingAwaitWarning --version 2.1.0-beta
<PackageReference Include="Lindhart.Analyser.MissingAwaitWarning" Version="2.1.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lindhart.Analyser.MissingAwaitWarning --version 2.1.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Lindhart.Analyser.MissingAwaitWarning, 2.1.0-beta"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Lindhart.Analyser.MissingAwaitWarning as a Cake Addin
#addin nuget:?package=Lindhart.Analyser.MissingAwaitWarning&version=2.1.0-beta&prerelease

// Install Lindhart.Analyser.MissingAwaitWarning as a Cake Tool
#tool nuget:?package=Lindhart.Analyser.MissingAwaitWarning&version=2.1.0-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

unused-task-warning

When using dependency injection and async-await pattern it is possible to end up with an interface with a method that returns a Task. If this interface method is used in a synchronous method there is a likelihood that it will erroneously be run as a fire and forget method (which will not trigger inbuilt warning CS4014). In this situation this analyser generates a warning.

Can both be used as a Visual Studio extension or preferably as a project analyser available from NuGet.

###Example:

using System.Threading.Tasks;

namespace AsyncAwaitProblem
{
	public interface ICallee
	{
		bool ProblemSolved { get; }
		Task SolveProblemAsync();
	}

	public class Callee : ICallee
	{
		public bool ProblemSolved { get; set; }

		public async Task SolveProblemAsync()
		{
			await Task.Delay(10);
			ProblemSolved = true;
		}
	}
	
	public class Caller
	{
		public bool DoCall()
		{
			ICallee xxx = new Callee();

			// This analyser will give a warning at the following line
			xxx.SolveProblemAsync(); // This is most likely an undesired fire and forget. 

			return xxx.ProblemSolved; // Will return false - we expected it to return true
		}
	}
}

Strict option

The analyser also has a strict option that can be enabled by folding out the analyser in the dependency tree in Visual Studio, right clicking the strict rule and selecting the severity.

The strict option also gives warnings in lambda functions and storing the result of a Task returning method in a variable.

Notes

Note that this analyser currently only checks for the currently known awaitable types. If another 'Awaitable' type is returned this analyser will not give the warning. This might be fixed in a future version.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (68)

Showing the top 5 NuGet packages that depend on Lindhart.Analyser.MissingAwaitWarning:

Package Downloads
DogmaSolutions.Contracts

Package Description

Cortside.Common.Correlation

Package Description

DogmaSolutions.Log4NetExtensions

Package Description

Cortside.Common.IoC

Cortside.Common.IoC Class Library

Cortside.Common.BootStrap

Cortside.Common.BootStrap Class Library

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Lindhart.Analyser.MissingAwaitWarning:

Repository Stars
RayTale/Ray
项目停止更新,新项目:https://github.com/RayTale/Vertex
MrCMS/MrCMS
Mr CMS is an open source C# MVC CMS Framework
veldtech/bot
Miki Discord Bot
Version Downloads Last updated
2.1.0-beta 7,288 8/11/2021
2.0.0 523,026 12/7/2020
2.0.0-beta2 507 10/26/2020
2.0.0-beta 304 10/26/2020
1.2.1 43,412 9/28/2020
1.2.1-beta 546 5/8/2020
1.2.0 327,333 6/6/2019
1.2.0-beta 506 4/16/2019
1.0.1 159,028 8/10/2018
1.0.0 35,165 1/6/2018