设置:
public class Class1
{
public static void doStuff()
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlServer("MyConnectionString");
var userStore = new UserStore<ApplicationUser, MyRole, ApplicationDbContext, Guid>(
new ApplicationDbContext(optionsBuilder.Options)
); // the userStore.Users property shows already the exception in the debugger
AspNetUserManager<ApplicationUser> userManager = new AspNetUserManager<ApplicationUser>(
userStore,
null,
new PasswordHasher<ApplicationUser>(),
new List<UserValidator<ApplicationUser>>() { new UserValidator<ApplicationUser>() },
null,
null,
null,
null,
null
);
var x = userManager.Users; // exception throw (see next code snipped)
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, MyRole, Guid>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder); // after userManager.Users is called the exception is thrown here
}
}
并且在WebForms-Project中只是:
public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { Class1.doStuff(); } }
Exception:System.MissingMethodException:“方法”:“ Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder
1.HasIndex(System.Linq.Expressions.Expression
1>)”。。Net Standard 2.0项目的配置:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.1" /> </ItemGroup> </Project>
https://github.com/dotnet/aspnetcore/issues/8467他们在这里说要更新为“ Microsoft.AspNetCore.Identity” 3.x,但我不能这样做,因为它与.Net Standard 2.0项目不兼容,并且WebForms项目需要它。参考:
[所以,我的问题
是如果有人知道一种解决方法,以另一种方式生成Usermanager ...我需要使用aspnetcore-identity获取和设置用户(并验证)(数据库等已经迁移) 这是我在使用aspnetcore.identity时在“发现不同版本之间的冲突”或System.MissingMethodException中发布的问题之一,但我想对此进行解释...