Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet-sdk-10.0.100-preview.1.25103.13] Some apps retarget failed with CS0121 and CS0428 System.Linq errors #112462

Open
Junjun-zhao opened this issue Feb 10, 2025 · 12 comments

Comments

@Junjun-zhao
Copy link
Member

Application Name: Smartstore, blog, nopCommerceNetCore
OS: Windows 10 22H2
CPU: X64
.NET Build Number: dotnet-sdk-10.0.100-preview.1.25103.13
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2379210

Github Link:
https://github.com/smartstore/Smartstore
https://github.com/sagebind/blog
https://github.com/nopSolutions/nopCommerce

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.25103.13-win-x64 + retarget10.0: Fail

Description :
When retargeting Smartstore app to .NET 10, it is built failed with CS0212 and CS0428 errors:

error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)' and 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToListAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.ToListAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToArrayAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.ToArrayAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToDictionaryAsync<TSource, TKey, TElement>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TKey>, System.Func<TSource, TElement>, System.Collections.Generic.IEqualityComparer<TKey>?, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.ToDictionaryAsync<TSource, TKey, TElement>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TKey>, System.Func<TSource, TElement>, System.Collections.Generic.IEqualityComparer<TKey>?, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.CountAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.CountAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Select<TSource, TResult>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TResult>)' and 'System.Linq.AsyncEnumerable.Select<TSource, TResult>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TResult>)'
error CS0428: Cannot convert method group 'Count' to non-delegate type 'int'. Did you intend to invoke the method?

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

  1. Create a .NET 9 Console project.
  2. Install latest version of System.Linq.Async nuget package.
  3. Add a Test.cs class file with below code:
 public interface ITestInterface
 {
     IEnumerable<string> EnumerateFiles(string? pattern = "*", bool deep = false)
         => throw new NotImplementedException();

     IAsyncEnumerable<string> EnumerateFilesAsync(string? pattern = "*", bool deep = false, CancellationToken cancelToken = default)
        => EnumerateFiles(pattern, deep).ToAsyncEnumerable();

     //IAsyncEnumerable<string> EnumerateFilesAsync(string? pattern = "*", bool deep = false, CancellationToken cancelToken = default)
     //    => EnumerateFiles(pattern, deep).ToAsyncEnumerable();

     async ValueTask<int> CountFilesAsync(string? pattern = "*", bool deep = true, CancellationToken cancelToken = default)
         => await EnumerateFilesAsync(pattern, deep, cancelToken).CountAsync(cancellationToken: cancelToken);

 }

 public partial interface IRuleService
 {
     Task<ITestInterface> CreateExpressionGroupAsync(int ruleSetId, bool includeHidden = false);
 }

 public static class TestStaticClass
 {
     private static readonly IRuleService _ruleService;

     public static IAsyncEnumerable<TResult> SelectAwait<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, Task<TResult>> selector)
     {
         return source.ToAsyncEnumerable().SelectAwait(x => new ValueTask<TResult>(selector(x)));
     }


     public static void TestMethod()
     {
         int[] ruleSetIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

         var expressions = ruleSetIds
             .SelectAwait(id => _ruleService.CreateExpressionGroupAsync(id))
             .Where(x => x != null);

         var expressions2 = ruleSetIds
             .SelectAwait(id => _ruleService.CreateExpressionGroupAsync(id))
             .ToArrayAsync();

         var expressions3 = ruleSetIds
             .SelectAwait(id => _ruleService.CreateExpressionGroupAsync(id))
             .Take(1);

         var expressions4 = ruleSetIds
             .SelectAwait(id => _ruleService.CreateExpressionGroupAsync(id))
             .Select(i => i != null);

         var expressions5 = ruleSetIds
              .SelectAwait(id => _ruleService.CreateExpressionGroupAsync(id))
              .AnyAsync();
     }
 }

 internal class CachingResult<TResult, TEntity>
 {
     public async Task<(object Value, int Count)> ConvertQueryAsyncResult(TResult queryResult)
     {
         object result = queryResult;
         var list = await ((IAsyncEnumerable<TEntity>)result).ToListAsync();
         return (list, list.Count);
     }
 }
  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 Result:
Build successful.

Actual Result:
Build Failed with below errors:

error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToListAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.ToListAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0428: Cannot convert method group 'Count' to non-delegate type 'int'. Did you intend to invoke the method?
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)' and 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.CountAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.CountAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)' and 'System.Linq.AsyncEnumerable.ToAsyncEnumerable<TSource>(System.Collections.Generic.IEnumerable<TSource>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'System.Linq.AsyncEnumerable.Where<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.ToArrayAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.ToArrayAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Take<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, int)' and 'System.Linq.AsyncEnumerable.Take<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, int)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.Select<TSource, TResult>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TResult>)' and 'System.Linq.AsyncEnumerable.Select<TSource, TResult>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, TResult>)'
error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)' and 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Threading.CancellationToken)'

DotNet Info:

.NET SDK:
 Version:           10.0.100-preview.1.25103.13
 Commit:            9035d02b05
 Workload version:  10.0.100-manifests.bf5105ba
 MSBuild version:   17.14.0-preview-25073-02+291a81087

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.1.25103.13\

Host:
  Version:      10.0.0-preview.1.25080.5
  Architecture: x64
  Commit:       b98cabca12

.NET SDKs installed:
  10.0.100-preview.1.25103.13 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.0-preview.1.25103.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.0-preview.1.25080.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.0-preview.1.25080.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Findings:
After investigating, we found all the methods or properties thrown from errors come from System.Linq.Async nuget package.

@dotnet-actwx-bot @dotnet/compat

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Feb 10, 2025
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Junjun-zhao
Copy link
Member Author

@marcpopMSFT Could you please have a look at this bug and help triage it? Thanks!

@marcpopMSFT marcpopMSFT transferred this issue from dotnet/sdk Feb 10, 2025
@Junjun-zhao
Copy link
Member Author

@jcouv Could you please take a look at this issue and confirm whether it is a blocker for .NET 10.0 Preview1 validation? Thanks

@jcouv
Copy link
Member

jcouv commented Feb 11, 2025

This doesn't look like a compiler issue. The extension method is defined in two assemblies given to the compiler (details below the fold).

If you remove the reference to System.Linq.Async then things compile file.
Is the problem that this test was using a nuget package which has now been replaced by APIs built into the BCL?
Tagging @stephentoub to advise.


First one:
System.Threading.Tasks.ValueTask<System.Collections.Generic.List<TSource>!> System.Linq.AsyncEnumerable.ToListAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, [System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)])
System.Linq.Async, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263

Second one:
System.Threading.Tasks.ValueTask<System.Collections.Generic.List<TSource>!> System.Linq.AsyncEnumerable.ToListAsync<TSource>(this System.Collections.Generic.IAsyncEnumerable<TSource>! source, [System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)])
System.Linq.AsyncEnumerable, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Here are the two references given to the compiler:
/reference:C:\Users\jcouv\.nuget\packages\system.linq.async\6.0.1\ref\net6.0\System.Linq.Async.dll
/reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\10.0.0-preview.1.25080.5\ref\net10.0\System.Linq.AsyncEnumerable.dll"

@jaredpar
Copy link
Member

Moving to runtime as this is caused by new APIs. Will let them decide how to proceed here.

@jaredpar jaredpar transferred this issue from dotnet/roslyn Feb 12, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis
Copy link
Member

This is something that got discussed here: #79782 (comment)

TL;DR we need a deprecation plan and document relevant workaround in cases where there are conflicts due to transitive dependencies.

@eiriktsarpalis eiriktsarpalis removed the untriaged New issue has not been triaged by the area owner label Feb 12, 2025
@eiriktsarpalis eiriktsarpalis added this to the 10.0.0 milestone Feb 12, 2025
@eiriktsarpalis
Copy link
Member

@Junjun-zhao Does the workaround described here address you immediate issue?

@Junjun-zhao
Copy link
Member Author

@eiriktsarpalis We have tried the workaround, two applications have worked with it. The third one is still in progress and I will update the result once it is completed.

There is another application also encountered CS0121 issue, could you please help look at this issue and help move to the right team if it is not. Thank you very much.

@Junjun-zhao
Copy link
Member Author

@eiriktsarpalis Besides the deprecation plan, will you be going to create a breaking change document for this change?

@eiriktsarpalis
Copy link
Member

.NET adding APIs that conflict with third party packages is fairly common, it isn't something we consider a breaking change. We will make sure that the legacy System.Linq.Async package includes guidance for users looking to move away from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants