【问题标题】:Cannot find all types required by the async modifier找不到 async 修饰符所需的所有类型
【发布时间】:2017-10-02 20:25:07
【问题描述】:

我收到以下两个编译器错误(Resharper 7.0.1 没有报告错误):

未定义或导入预定义类型“System.Runtime.CompilerServices.IAsyncStateMachine”

找不到“async”修饰符所需的所有类型。您是针对错误的框架版本还是缺少对程序集的引用?

但是这段代码不会编译:

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);
    }
}

我已经看到MSBuild doesn't find async required references,除了我有 VS 2012 NOT VS 11 Beta - 尽管它已安装。我还在一个全新的程序集中尝试了它,没有指向应用程序的 xaml 命名空间。

【问题讨论】:

    标签: silverlight task-parallel-library silverlight-5.0 async-await reactiveui


    【解决方案1】:

    您需要 Async Targeting Pack 来支持 Silverlight 5 中的 async

    【讨论】:

      【解决方案2】:

      我们刚刚发布了适用于 .NET Framework 4、Silverlight 4 和 5 以及 Windows Phone 7.5 的 Async 测试版:http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx

      【讨论】:

      • 为什么不用 WP7.1?一个项目只能针对WP7.1或者WP8.0,所以只支持WP7.5+是没用的。
      【解决方案3】:

      您不能在 Visual Studio 2012 中使用 AsyncCTP。您可以为 Silverlight 5 使用 Async Targeting Pack(可在 NuGet 上获得)。目前还没有适用于 Silverlight 4 的解决方案,不确定是否会有。

      【讨论】:

        猜你喜欢
        • 2018-07-13
        • 1970-01-01
        • 2012-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-09
        相关资源
        最近更新 更多