nam nam - 10 months ago 87
C# Question

What is Ambiguous call error in ASP.NET Core C# code?

What does the following error mean and how to resolve it?

The call is ambiguous between the following methods or properties: 'System.Security.Claims.PrincipalExtensions.FindFirstValue(System.Security.Claims.ClaimsPrincipal, string)' and 'System.Security.Claims.PrincipalExtensions.FindFirstValue(System.Security.Claims.ClaimsPrincipal, string)'


The References folder shows the following:

enter image description here

And the Using Statements in the relevant
file are as follows:

using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using ABCTest.Models;
using ABCTest.Models.AccountViewModels;
using ABCTest.Services;

Answer Source

You have an very old dependency on Microsoft.AspNet.Identity.EntityFramework. It is pulling all the old pre-rc2 packages in your solution and you end up with two assemblies with different name and different versions and compiler doesn't know which one to choose.

Together with ASP.NET Core Microsoft.AspNet.Identity.EntityFramework was renamed to Microsoft.AspNetCore.Identity.EntityFrameworkCore (notice the Core part) and its version should be 1.1.0 too with the rest of your ASP.NET Core packages.

Be careful when following very old tutorials (ones which refer Microsoft.AspNet.* or Microsoft.EntityFramework.* packages or ones that are older than July 2016) as they are based on the framework before the assemblies got renamed.