简体   繁体   English

如何修复调用构造函数“Void.ctor”时引发异常

[英]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.

相关问题 Autofac异常:无法解析构造函数&#39;Void .ctor的参数 - Autofac Exception: Cannot resolve parameter of constructor 'Void .ctor 在调用PowerShell时抛出异常“安全错误” - Exception thrown as “Security error” while invoking powershell 使用ImportingConstructor处理从ctor引发的异常 - Handle an exception thrown from ctor with ImportingConstructor 如何断言构造函数中抛出的异常? - How do I assert the exception thrown in the constructor? 访问数据时,如何解决“调用目标抛出了异常”? - How can I fix “exception has been thrown by the target of an invocation” while accessing data? 在构造函数中调用 ShellSettingsManager 会抛出 System.UnsupportedException。 如何解决这个问题? - Invoking ShellSettingsManager in Constructor throw System.UnsupportedException. How to fix this? c#Exception抛出(不在)构造函数中 - c# Exception Thrown at (not in) Constructor 捕获由 async void 方法抛出的异常 - Catch an exception thrown by an async void method 向多个收件人发送邮件时如何解决抛出的异常? - How to fix exception thrown when sending mail message to multiple recipients? 调用测试驱动程序时发生异常 - Exception while invoking a test driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM