我正在-net Core 2 api中实现身份验证,并在以下代码后发现此错误:
StartUp.cs:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<MyContext>()
.AddDefaultTokenProviders();
MyContext.cs:
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class MyContext: IdentityDbContext<IdentityUser>
{
public MyContext(DbContextOptions<MyContext> opt)
: base(opt) { }
public DbSet<Room> Rooms{ get; set; }
}
MyCOntext.cs中的错误:
'IdentityUser' is an ambiguous reference between 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser' and 'Microsoft.AspNetCore.Identity.IdentityUser'
谢谢大家。
答案 0 :(得分:0)
由于IdentityUser
存在于上述两个命名空间中,因此您需要删除其中之一,或者像下面这样明确指定using
使用哪个命名空间:
using IdentityUser = Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser
答案 1 :(得分:0)
这个问题发生在我身上,就我而言,我发现问题发生了 因为旧的NuGet包
我安装了Microsoft.AspNetCore.Identity.EntityFrameworkCore : v 1.1.0
但是当前版本为3.1.4
,因此我只对其进行了更新,一切正常。