5

There is a old Asp.Net WebSite Project, opened in VS 2015 which targeting a 4.0 FrameWork Version, when I am trying to build it it gives me below error:

The call is ambiguous between the following methods or properties: System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource) and System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource)

which both method signature looks exactly identical.

Here it code from the class:

using System;
using System.Collections.Generic; // Gray out
using System.Linq;
using System.Web; // Gray out
using System.Web.Routing;
using System.Web.UI; // Gray out

public class UrlRoute
{

  public static string RegisterRoutes(string routes)
  {
    string MainUrl = routes;
    string result = "";
    if (MainUrl.Contains('\\')==true)
    {
      result = "CMS"
    }
    return result;
  }
}

Project Properties:

Reference

Framework Details:

FrameWork Details

I tried solution from SO but none of them worked [delete bin folder, check unresolved references], don't understand the reason behind the error!

EDIT:

Same is happening for Last() and all that extension method from System.Linq:

Error CS0121 The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Last(System.Collections.Generic.IEnumerable)' and 'System.Linq.Enumerable.Last(System.Collections.Generic.IEnumerable)'

Will love to share any other configuration/code if required.

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84

1 Answers1

4

You are most likely referencing two versions of System.Linq.dll. Project should use version from GAC, not local copy from BIN.

Try to find and remove explicit reference to System.Linq.dll in your C# project.

P.S. And if you have multiple projects in the solution, make sure they all target same version of .NET Framework.

Nenad
  • 24,809
  • 11
  • 75
  • 93
  • @PrashantPimpale Glad it worked. In case subsequent build puts `System.Linq.dll` back the application folder, then you need to check/clean project references. – Nenad Sep 18 '19 at 13:09
  • Can you help me with this: https://stackoverflow.com/questions/58020793/asp-net-core-download-ssrs-reports-in-pdf-format-on-client-browser-by-its-url – Prashant Pimpale Sep 20 '19 at 11:01