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

Compilation error #55855

Closed
kant2002 opened this issue Jul 16, 2021 · 14 comments · Fixed by #55828
Closed

Compilation error #55855

kant2002 opened this issue Jul 16, 2021 · 14 comments · Fixed by #55828
Labels
area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner

Comments

@kant2002
Copy link
Contributor

kant2002 commented Jul 16, 2021

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);
}

kant2002 referenced this issue in kant2002/runtimelab Jul 16, 2021
after introduction of these functions to LINQ
This is requires bump of expected version in global.json

Closes #1334
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Linq untriaged New issue has not been triaged by the area owner labels Jul 16, 2021
@ghost
Copy link

ghost commented Jul 16, 2021

Tagging subscribers to this area: @eiriktsarpalis
See info in area-owners.md if you want to be subscribed.

Issue Details

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>)'
Author: kant2002
Assignees: -
Labels:

area-System.Linq, untriaged

Milestone: -

@jkotas jkotas transferred this issue from dotnet/runtimelab Jul 16, 2021
@stephentoub
Copy link
Member

stephentoub commented Jul 16, 2021

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.

@jkotas
Copy link
Member

jkotas commented Jul 16, 2021

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

@jkotas jkotas closed this as completed Jul 16, 2021
@jkotas jkotas reopened this Jul 16, 2021
@kant2002
Copy link
Contributor Author

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

@kant2002
Copy link
Contributor Author

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.

@MichalStrehovsky
Copy link
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?

@kant2002
Copy link
Contributor Author

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.

@MichalStrehovsky
Copy link
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.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 20, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 20, 2021
@RussKie
Copy link
Member

RussKie commented Aug 3, 2021

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

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Aug 3, 2021

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.

@RussKie
Copy link
Member

RussKie commented Aug 3, 2021

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

@MichalStrehovsky
Copy link
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.

@RussKie
Copy link
Member

RussKie commented Aug 3, 2021

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

@MichalStrehovsky
Copy link
Member

dotnet/docs#25436

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

@ghost ghost locked as resolved and limited conversation to collaborators Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants