.NET Core 3.0迁移错误IAsyncEnumerable<T>同时存在于System.Interactive.Async和System.Runtime

.NET Core 3.0 migration error IAsyncEnumerable<T> exists in both System.Interactive.Async and System.Runtime

我正在尝试将项目从 .net core 2.2 迁移到 3.0。

我收到错误:

Error CS0433 The type 'IAsyncEnumerable< T >' exists in both 'System.Interactive.Async, Version=3.2.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' and 'System.Runtime, Version=4.2.1.0

我在这里尝试了一个建议: https://github.com/aspnet/EntityFrameworkCore/issues/15047 建议强制更新到 System.Interactive.Async 4.0.0。 (我将此引用添加到我的项目中)。

但是我有另一个错误: 对类型 'IAsyncEnumerable<>' 的引用声称它在 'System.Interactive.Async' 中定义,但找不到

我正在使用 IAsyncQueryProvider,似乎是它导致了问题。

我在 2.2 中没有这些问题,目前我找不到任何解决方法。

我也尝试过强制更新到 System.Runtime 4.3.1,但没有帮助。

Panatiotis 的建议有效,我添加了对 Microsoft.EntityFrameworkCore 3.0 的引用并且有效。对于我的情况,.NET Core 2.2 中不需要此参考。

虽然问题已经得到解答,但我在这里找到了:https://github.com/dotnet/efcore/issues/14239 一个人遇到了与这个问题类似的问题,并且与我的问题几乎相同。

使用EntityFrameworkCore (3.1.1) 和IAsyncEnumerable 接口的netcoreapp3.1 项目。 我的构建以这个错误结束:

error CS0433: The type 'IAsyncEnumerable' exists in both 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

问题是由使用 nuget restore 命令(不是 dotnet restore)引起的,我有一个旧版本的 nuget.exe。升级到最新版本 nuget.exe 修复了构建。

作为在 .NET Core 2.2 上偶然发现这个但没有迁移到 3+ 的人,我在 same issue referenced above 上找到了另一个解决方案。 引用的项目文件自此评论以来已修改,因此 here's a direct link.

在我的例子中,我将这个目标添加到项目文件中:

<Target Name="AddAssemblyAliasToReactiveAsync"
        AfterTargets="ResolveAssemblyReferences"
        Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
  <ItemGroup>
    <ReferencePath Condition=" '%(FileName)' == 'System.Interactive.Async' ">
      <Aliases>reactive</Aliases>
    </ReferencePath>
  </ItemGroup>
</Target>