Cannot find all types required by the async modifier

João Bragança picture João Bragança · Oct 20, 2012 · Viewed 9.8k times · Source

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.

Answer

Stephen Cleary picture Stephen Cleary · Oct 20, 2012

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