Lindhart.Analyser.MissingAwaitWarning 1.2.0

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. In this situation this analyser generates a warning.

Install-Package Lindhart.Analyser.MissingAwaitWarning -Version 1.2.0
dotnet add package Lindhart.Analyser.MissingAwaitWarning --version 1.2.0
<PackageReference Include="Lindhart.Analyser.MissingAwaitWarning" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lindhart.Analyser.MissingAwaitWarning --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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
		}
	}
}

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.

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
		}
	}
}

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.

Release Notes

Updated to include all currently known awaitable types.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.2.0 8,379 6/6/2019
1.2.0-beta 171 4/16/2019
1.0.1 65,919 8/10/2018
1.0.0 15,721 1/6/2018