当我结合使用Pomelo.EntityFrameworkCore.MySql和Microsoft.AspNetCore.Identity时,我会得到这个错误。
我的依赖性是错的吗?类似的问题已经报告了2021年,但与较早的版本。
https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1510
TypeLoadException: Method 'IsValid' in type 'Pomelo.EntityFrameworkCore.MySql.Update.Internal.MySqlModificationCommandBatch' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=6.0.1.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.csproj
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0-rc.2.21480.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-preview.3.22175.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-preview.3.22175.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySqlConnector" Version="2.1.8" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
</ItemGroup>ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
}Programm.cs
var connectionString = builder.Configuration.GetConnectionString("Default");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
});
builder.Services.AddIdentity<IdentityUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 8;
options.Password.RequireLowercase = true;
options.Password.RequireUppercase = true;
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
options.User.RequireUniqueEmail = true;
}).AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
options.AccessDeniedPath = "/Account/AccessDenied";
});
var app = builder.Build();寄存器
public class RegisterModel : PageModel
{
private readonly UserManager<IdentityUser> userManager;
public RegisterModel(UserManager<IdentityUser> userManager)
{
this.userManager = userManager;
}
[BindProperty] public RegisterViewModel RegisterViewModel { get; set; }
..
..
public async Task<IActionResult> OnPostAsync()
{...
var result = await userManager.CreateAsync(user, RegisterViewModel.Password); // ERROR
}发布于 2022-04-18 10:52:08
尝试合并已安装的包版本,特别是预览版本(特别是EF 7)。只更新左边:
<ItemGroup>
...
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
...
</ItemGroup>发布于 2022-04-30 01:51:08
我在VS2022上也面临着同样的问题。我通过将EF工具的版本从7.0.0改为6.0.4和6.0.1中的Pomelo来解决这个问题;另一个选择是在包管理器控制台中运行"update-database“命令。希望能帮上忙!
https://stackoverflow.com/questions/71904217
复制相似问题