Skip to content

Compilation error #55855

Closed
Closed

Description

@kant2002

When on .NET SDK 6.0.100-preview.7.21359.1

error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Select<TSource, TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource, TResult>)' and 'Internal.CommandLine.Enumerable.Select<T, U>(System.Collections.Generic.IEnumerable<T>, System.Func<T, U>)'

This is code from here

public static IEnumerable<U> Select<T, U>(this IEnumerable<T> values, Func<T, U> func)
{
Debug.Assert(values != null);
foreach (T value in values)
{
yield return func(value);
}
}

and here
public static IEnumerable<T> Concat<T>(this IEnumerable<T> first, IEnumerable<T> second)
{
return Linq.Enumerable.Concat(first, second);
}

Activity

  1. added a commit that references this issue on Jul 16, 2021
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jul 16, 2021
  3. transferred this issue fromdotnet/runtimelabon Jul 16, 2021
  4. stephentoub commented on Jul 16, 2021

    @stephentoub
    Member

    What is Internal.CommandLine ? It seems like there are two equally valid extension methods, and so the compiler is telling you it doesn't know which to pick. That's by design.

  5. jkotas commented on Jul 16, 2021

    @jkotas
    Member

    It is command line parser for crossgen2 tool and other tools.

  6. reopened this on Jul 16, 2021
  7. kant2002 commented on Jul 18, 2021

    @kant2002
    ContributorAuthor

    I update original issue with locations of the code which was breaking for me.

  8. kant2002 commented on Jul 20, 2021

    @kant2002
    ContributorAuthor

    Is this happens because of implicit namespace imports?
    This is only area which I can guess can differ between .NET 6 Preview 4 and .NET 6 Preview 7.

  9. MichalStrehovsky commented on Jul 20, 2021

    @MichalStrehovsky
    Member

    Oh wow - https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates#use-the-new-program-style

    For console applications, the following directives are implicitly included in every source file in the application:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Json;

    🤮

    Looks like the docs miss one very important piece of information: how do I tell MSBuild "HELL NO!" to this?

  10. kant2002 commented on Jul 20, 2021

    @kant2002
    ContributorAuthor

    Yes. I confirm that System.Linq added to ILCompiler.ImplicitNamespaceImports.cs, and that's behavior is by default.

    There only 2 places in repo where src/coreclr/tools/Common/CommandLine/Enumerable.cs file included.

    <Compile Include="..\..\Common\CommandLine\Enumerable.cs" />

    and
    <Compile Include="..\Common\CommandLine\Enumerable.cs" Link="CommandLine\Enumerable.cs" />

    so I assume I should add <DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports> in that files instead of removing source code. Then I should add same property to ILC where I discover the issue.

  11. MichalStrehovsky commented on Jul 20, 2021

    @MichalStrehovsky
    Member

    Hm, that disables the support for <Import Include="Blah" /> completely.

    I think we'll want <DisableImplicitNamespaceImports_DotNet>true</DisableImplicitNamespaceImports_DotNet> and put that in src\coreclr\tools\Directory.Build.props so that we never have to deal with that in our tools again.

  12. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 20, 2021
  13. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 20, 2021
  14. RussKie commented on Aug 3, 2021

    @RussKie
    Contributor

    You could also do <Import Remove="System.Linq" /> in your csproj/props files to exclude specific imports.

  15. MichalStrehovsky commented on Aug 3, 2021

    @MichalStrehovsky
    Member

    You could also do <Import Remove="System.Linq" /> in your csproj/props files to exclude specific imports.

    Not a fan of that. dotnet/sdk#18825 is already discussing adding new additional usings that are going to cause more build breaks. E.g. the proposed System.Diagnostics addition is going to break the build for Chocolatey, Microsoft Terminal, azure pipelines agent and countless other projects.

    The discussion shouldn't really be about what other namespaces we add by default, but what namespaces should be removed from the defaults.

    The only ones that are maybe, maybe, okay are System and System.Collections.Generic. Everything else: I don't want that in my projects. Even the collections might be an overkill.

  16. RussKie commented on Aug 3, 2021

    @RussKie
    Contributor

    My suggestion was to show another way of solving the issue, and not discuss global usings in general.

  17. MichalStrehovsky commented on Aug 3, 2021

    @MichalStrehovsky
    Member

    Understood - I was just trying to point out that solution wouldn't satisfy the "so that we never have to deal with that in our tools again" part.

  18. RussKie commented on Aug 3, 2021

    @RussKie
    Contributor

    Oh wow - docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates#use-the-new-program-style
    Looks like the docs miss one very important piece of information: how do I tell MSBuild "HELL NO!" to this?

    dotnet/docs#25436

  19. MichalStrehovsky commented on Aug 3, 2021

    @MichalStrehovsky
    Member

    dotnet/docs#25436

    @kant2002 already has a pull request in flight: dotnet/docs#25232

  20. ghost locked as resolved and limited conversation to collaborators on Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Infrastructure-coreclrOnly use for closed issuesuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions