The type or namespace name 'async' could not be found

I am trying to use the following method in a WPF application .NET Framework 4 Client Profile but I receive this error:

The type or namespace name 'async' could not be found

I am using

using System.Threading.Tasks;

Any idea what could be wrong? Thanks in advance

private async Task SumPageSizesAsync()
{
    HttpClient client = new HttpClient();
    Task<byte[]> getContentsTask = client.GetByteArrayAsync(url);
    byte[] urlContents = await getContentsTask;   
}

I am using VS 2010

Jon Skeet
people
quotationmark

Well, there are two things:

  • You need to be using a C# 5 compiler, e.g. VS2012. If you're using VS2010, you can't use async. Given the error message, I suspect that you're using the wrong compiler version.
  • You need to use the Microsoft.Bcl.Async NuGet package to bring in the appropriate library support for .NET 4.

people

See more on this question at Stackoverflow