11

I have an old ASP.NET Web Form project that I need to add an async library too. I've upgraded it to .NET Framework v4.5.1. It run and compiles perfectly with Visual Studio 2013.

However, when I open it with Visual Studio 2015, it wont compile. Every async call has a TaskAwaiter does not implement INotifyCompletion error.

For instance, the following code:

public async Task AsyncDelay()
{
    await Task.Delay(1);
}

Throw the following error:

CS4027 'TaskAwaiter' does not implement 'INotifyCompletion'

Any help at all would be appreciated.

Dale Alleshouse
  • 1,627
  • 2
  • 17
  • 24
  • 2
    That code fails completely differently for me: "Test.cs(17,9): error CS1997: Since 'Test.AsyncDelay()' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return '`Task`'?" It's not at all clear what you're trying to return, to be honest. What are you trying to achieve? I'd be really surprised to see this compile in any scenario. – Jon Skeet Dec 10 '15 at 17:41
  • @JonSkeet - Sorry, I corrected the code above. I didn't mean to put that return statement in there. I'll also note that that code isn't really doing anything, I just wanted to demonstrate that all my async calls are broken. – Dale Alleshouse Dec 10 '15 at 18:31

2 Answers2

17

I finally found the issue. This nuget package was installed

https://www.nuget.org/packages/Microsoft.CompilerServices.AsyncTargetingPack/1.0.1

That was there to support older version of Visual Studio. I remove this and everything works.

I wasted way too much time on this one...

Dale Alleshouse
  • 1,627
  • 2
  • 17
  • 24
  • 1
    i dont know how you sleuthed that one (care to elaborate?) but kudos +1 – wal Feb 29 '16 at 03:35
  • 1
    Despite "uninstalling" NuGet package(s), or not having them installed, I still had a reference to ```Microsoft.CompilerServices.AsyncTargetingPack.Net4``` that needed to be deleted. – starlocke Aug 16 '16 at 15:11
  • This was helpful. Faced this issue while targeting 4.6.1 from 4.0, removed this – eswara amirthan s Jun 23 '22 at 12:44
3

I faced with this issue today, I think it may helps to someone: Microsoft.CompilerServices.AsyncTargetingPack is deprecated, but there is another package

https://www.nuget.org/packages/Microsoft.Bcl.Async

I've removed this from the project, and now everything is fine.

sziluetta
  • 31
  • 2