[英]How to fix An exception was thrown while invoking the constructor 'Void .ctor
I try to add-migration to one of my contexts but i find this error我尝试将迁移添加到我的一个上下文中,但我发现了这个错误
Autofac.Core.DependencyResolutionException: An exception was thrown while activating weno.Infrastructure.Data.DataContext.AppDbContext.
---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.EntityFrameworkCore.DbContextOptions`1
[weno.Infrastructure.Data.DataContext.AppDbContext], MediatR.IMediator)' on type 'AppDbContext'.
---> System.TypeLoadException: Method 'AppendIdentityWhereCondition' in type 'MySql.EntityFrameworkCore.MySQLUpdateSqlGenerator'
from assembly 'MySql.EntityFrameworkCore, Version=5.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
does not have an implementation.
at MySql.EntityFrameworkCore.Extensions.MySQLServiceCollectionExtensions.<>c.<AddEntityFrameworkMySQL>b__0_3(ServiceCollectionMap m)
I have DefaultInfrastructureModule code like this:我有这样的 DefaultInfrastructureModule 代码:
builder.RegisterGeneric(typeof(AppRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(AccountingRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
.
.
.
}
And my AppDbContext like this:我的 AppDbContext 是这样的:
public class AppDbContext : DbContext
{
private readonly IMediator? _mediator;
public AppDbContext(DbContextOptions<AppDbContext> options, IMediator? mediator)
: base(options)
{
_mediator = mediator;
}
public DbSet<ToDoItem> ToDoItems => Set<ToDoItem>();
public DbSet<Project> Projects => Set<Project>();
.
.
.
}
How to fix this exception, Note that I want to dealing with 3 source Database.如何修复此异常,注意我要处理 3 源数据库。
Finally I fix it in my case with change MySql.EntityFrameworkCore
package to Pomelo.EntityFrameworkCore.MySql
and it's worked successfully.最后,我通过将
MySql.EntityFrameworkCore
package 更改为Pomelo.EntityFrameworkCore.MySql
来修复它,并且它工作成功。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.