Pomelo.EntityFrameworkCore.MySql.Update 中类型的 TypeLoadException 方法 'IsValid' 没有实现
TypeLoadException Method 'IsValid' in type in Pomelo.EntityFrameworkCore.MySql.Update does not have an implementation
当我将 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
}
尝试合并已安装的软件包版本,尤其是预览版本(尤其是 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>
我在 VS2022 swagger 上遇到了同样的问题。我设法通过将 EF 工具的版本从 7.0.0 更改为 6.0.4 并将 Pomelo 的版本更改为 6.0.1 来解决它;
另一种选择是在程序包管理器控制台中使用 运行 "update-database" 命令。
希望对您有所帮助!
当我将 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
}
尝试合并已安装的软件包版本,尤其是预览版本(尤其是 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>
我在 VS2022 swagger 上遇到了同样的问题。我设法通过将 EF 工具的版本从 7.0.0 更改为 6.0.4 并将 Pomelo 的版本更改为 6.0.1 来解决它; 另一种选择是在程序包管理器控制台中使用 运行 "update-database" 命令。 希望对您有所帮助!