Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name 'async' could not be found [duplicate]

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

like image 969
GibboK Avatar asked Jan 14 '14 08:01

GibboK


2 Answers

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.
like image 171
Jon Skeet Avatar answered Oct 23 '22 02:10

Jon Skeet


In my case the return type was missing, message was cause by code:

private async button1_Click(object sender, EventArgs e)

and should be

private async void button1_Click(object sender, EventArgs e)
like image 34
Tomas Kubes Avatar answered Oct 23 '22 02:10

Tomas Kubes