如何修复调用构造函数 'Void .ctor 时抛出异常
How to fix An exception was thrown while invoking the constructor 'Void .ctor
我尝试将迁移添加到我的上下文之一,但我发现了这个错误
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)
我有这样的 DefaultInfrastructureModule 代码:
builder.RegisterGeneric(typeof(AppRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(AccountingRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
.
.
.
}
我的 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>();
.
.
.
}
如何解决这个异常,
请注意,我想处理 3 个源数据库。
最后,我通过将 MySql.EntityFrameworkCore
包更改为 Pomelo.EntityFrameworkCore.MySql
来修复它,它成功地工作了。
我尝试将迁移添加到我的上下文之一,但我发现了这个错误
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)
我有这样的 DefaultInfrastructureModule 代码:
builder.RegisterGeneric(typeof(AppRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(AccountingRepository<>))
.As(typeof(IRepository<>))
.As(typeof(IReadRepository<>))
.InstancePerLifetimeScope();
.
.
.
}
我的 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>();
.
.
.
}
如何解决这个异常, 请注意,我想处理 3 个源数据库。
最后,我通过将 MySql.EntityFrameworkCore
包更改为 Pomelo.EntityFrameworkCore.MySql
来修复它,它成功地工作了。