Skip to content

[dotnet-sdk-10.0.100-preview.1.25110.2] Ambiguous call for SingleOrDefaultAsync method between Microsoft.EntityFrameworkCore nuget package and System.Linq.AsyncEnumerable.dll in sdk #112519

Closed
@Junjun-zhao

Description

@Junjun-zhao

Description

When retargeting SCM2020 app to .NET 10, it is built failed with CS0121 error:

The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.SingleOrDefaultAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>, System.Threading.CancellationToken)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource, bool>>, System.Threading.CancellationToken)'

Reproduction Steps

Minimal Repro Steps:(Demo attached:ConsoleTest.zip)
Make sure the machine has dotnet-sdk-10.0.100-preview.1.25110.2 installed.

  1. Create a .NET 9 Console project.
  2. Install Microsoft.EntityFrameworkCore 3.1.4 NuGet package.
  3. Program.cs below code:
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class AppDbContext : DbContext
{
    public DbSet<Person> People { get; set; }
}

class Program
{
    static async Task Main(string[] args)
    {
        var dbContext = new AppDbContext();
        dbContext.People.AddRange(new Person { Id = 1, Name = "test1" }, new Person { Id = 2, Name = "test2" });
        await dbContext.SaveChangesAsync();
        var person = await dbContext.People.SingleOrDefaultAsync(p => p.Name == "test1");
        Console.WriteLine(person?.Name);
    }
}
  1. Retarget the project to .NET 10:
<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net10.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
</PropertyGroup>
  1. Build the project.

Expected behavior

Build successful.

Actual behavior

Build Failed with below errors:

The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.SingleOrDefaultAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>, System.Threading.CancellationToken)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource, bool>>, System.Threading.CancellationToken)'

Regression?

Yes

Verify Scenarios:
1). Windows10 21h2 x64 + dotnet-sdk-8.0.405 + default target 8.0: Pass
2). Windows10 21h2 x64 + dotnet-sdk-9.0.102 + retarget 9.0: Pass
3). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25103.13 + default 8.0: Pass
4). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25110.2 + default 8.0: Pass
5). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25103.13-win-x64 + retarget10.0: Fail
​6). Windows10 21h2 x64 + dotnet-sdk-10.0.100-preview.1.25110.2-win-x64 + retarget10.0: Fail

Known Workarounds

If we upgrade the 'Microsoft.EntityFrameworkCore' nuget package from 3.1.14 to latest version, the problem will disappear.

Configuration

Application Name: SCM2020
OS: Windows 10 22H2
CPU: X64
.NET Build Number: dotnet-sdk-10.0.100-preview.1.25110.2
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2382358
Github Link: https://github.com/gcm10000/SCM2020

Other information

Findings:
After investigating, we found:
1.The ambiguous call for SingleOrDefaultAsync() method comes from Microsoft.EntityFrameworkCore NuGet package and it conflicts with "shared\Microsoft.NETCore.App\10.0.0-preview.1.25080.5\System.Linq.AsyncEnumerable.dll". If we upgrade the 'Microsoft.EntityFrameworkCore' nuget package from 3.1.14 to latest version, the problem will disappear.

  1. We have another bug #2379210 which has similar error which comes from System.Linq.Async nuget package. In this bug, dev provides a workaround by adding all to the System.Linq.Async nuget package and it works for the apps in that bug.

We tried the same way for Microsoft. EntityFrameworkCore nuget package but it doesn't work for it.

<PackageReference Include="Microsoft. Entity Framework Core" Version="3.1.14">
<ExcludeAssets>all</ExcludeAssets>

</PackageReference>

@dotnet-actwx-bot @dotnet/compat

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions