Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

519
Views
.net6 & MoreLinq : Call is ambiguous between System.Linq.Enumerable.DistinctBy and MoreLinq.MoreEnumerable.DistinctBy

Recently I upgraded one of my projects to use .NET 6. Earlier I was using MoreLinq library to use DistinctBy() to apply it on the specific property.

Now as I upgraded TargetFramework to .NET 6, this change come up with inbuilt support to DistinctBy().

Now the compiler is confused about which DistinctBy() needs to select, I can't rely on System.Linq, because the removal of using MoreLinq will cause multiple other errors.

I know if we face ambiguity between the same methods then we can use using alias, but I am not sure how to use using alias for Linq extension methods.

Here is the error:

enter image description here

I am able to replicate the same issue in the below fiddle

Try online

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can't alias an extension method, but you can call the extension like a normal method, using the full namespace. After all, extension methods are really just syntactic sugar. For example (using the same data you provided in your fiddle):

var inputs =  new []
{
    new {Name = "Bruce wayne", State = "New York"},
    new {Name = "Rajnikant", State = "Tamil Nadu"},
    new {Name = "Robert Downey jr", State = "Pennsylvania"},
    new {Name = "Dwane Johnson", State = "Pennsylvania"},
    new {Name = "Hritik", State = "Maharashtra"}
};
    
var net6DistinctBy = System.Linq.Enumerable.DistinctBy(inputs, x => x.State);
var moreLinqDistinctBy = MoreLinq.MoreEnumerable.DistinctBy(inputs, x => x.State);
over 4 years ago · Santiago Trujillo Report

0

To avoid conflicts when using MoreLinq, while still using them as extension methods, you can import the MoreLinq methods that you need like this:

using static MoreLinq.Extensions.LagExtension;
using static MoreLinq.Extensions.LeadExtension;

So in your case you could just delete MoreLinq from your usings and then import any MoreLinq extension methods that you need in the file individually as shown above.

You can read about it on the MoreLinq Github page

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!