Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find all types required by the async modifier

I get the following two compiler errors (Resharper 7.0.1 reports no errors):

Predefined type 'System.Runtime.CompilerServices.IAsyncStateMachine' is not defined or imported

Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?

but this code will not compile:

public class Class1
{
    public Class1()
    {
        Um();
    }
    public async Task<DownloadStringCompletedEventArgs> Um()
    {
        var client = new WebClient();
        return await Observable.FromEvent<DownloadStringCompletedEventHandler, DownloadStringCompletedEventArgs>(x => client.DownloadStringCompleted += x,
                                    x => client.DownloadStringCompleted -= x);
    }
}

I've seen MSBuild doesn't find async required references already except that I have VS 2012 NOT VS 11 Beta - although it was installed. Also I tried it in a brand new assembly, no xaml namespace pointing to the application.

like image 853
João Bragança Avatar asked Oct 20 '12 09:10

João Bragança


3 Answers

You need the Async Targeting Pack to support async in Silverlight 5.

like image 115
Stephen Cleary Avatar answered Oct 20 '22 16:10

Stephen Cleary


We just released a beta of Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5: http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx.

like image 36
David Kean Avatar answered Oct 20 '22 16:10

David Kean


You cannot use AsyncCTP in Visual Studio 2012. You can use Async Targeting Pack (available on NuGet) for Silverlight 5. No solution is yet available for Silverlight 4, not sure if there will be any.

like image 38
Martin Suchan Avatar answered Oct 20 '22 15:10

Martin Suchan