Nito.AsyncEx + .Net-4.0 = 'AsyncContext' 不存在于命名空间 'Nito.AsyncEx'

Nito.AsyncEx + .Net-4.0 = 'AsyncContext' does not exist in the namespace 'Nito.AsyncEx'

我需要 运行 Nito.AsyncEx 使用面向 .Net-4.0 的库。我正在尝试以下简单代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TempNet40
{
    class Program
    {
        static void Main(string[] args)
        {
            Nito.AsyncEx.AsyncContext.Run(() => MainAsync(args));
        }

        static async void MainAsync(string[] args)
        {

        }
    }
}

当我的 lib 以 .Net-4.5 或更高版本为目标时,上面的代码编译 - 它在 .Net-4.0 上失败并出现错误:

The type or namespace name 'AsyncContext' does not exist in the namespace 'Nito.AsyncEx' (are you missing an assembly reference?)

Nito.AsyncEx(以及它的 .Net-4.0 依赖项:Microsoft.Bcl.Async)是使用 NuGet 安装的 - 我想对于 .Net-4.0,我需要引用另一个库......确实有人知道是哪一个吗?

我建议您使用 NuGet 安装它,这也将帮助您管理依赖项。

只需右键单击您的项目并select 管理 NuGet 包

如果您想自己查找依赖项,可以查看NuGet主页:http://www.nuget.org/packages/Nito.AsyncEx

我成功重现了你的问题。我通过将 Microsoft.Bcl 升级到版本 1.1.10

解决了这个问题