System.ArgumentException
HResult=0x80070057
Message=AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor.
This means that the configuration passed to AddDbContext will never be used.
If configuration is passed to AddDbContext, then 'MyDBContext' should declare a constructor that accepts a DbContextOptions<MyDBContext> and must pass it to the base constructor for DbContext.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.CheckContextConstructors[TContext]()
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContextService,TContextImplementation](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContextService,TContextImplementation](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext[TContext](IServiceCollection serviceCollection, Action` optionsAction, ServiceLifetime contextLifetime, ServiceLifetime optionsLifetime)
at WebApi1.Startup.ConfigureServices(IServiceCollection services) in C:\Users\pxm\source\repos\WebApi1\WebApi1\Startup.cs:line
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at WebApi1.Program.Main(String[] args) in C:\Users\pxm\source\repos\WebApi1\WebApi1\Program.cs:line

翻译:

已使用配置调用AddDbContext,但上下文类型“MyDBContext”仅声明一个无参数构造函数。这意味着传递给AddDbContext的配置将永远不会被使用。
如果将配置传递给AddDbContext,那么“MyDBContext”应该声明一个接受DbContextOptions<MyDBContext>的构造函数,并且必须将其传递给DbContext的基本构造函数。

解决方法:

MyDBContext添加一个DbContextOptions<MyDBContext>类型参数的构造函数

AddDbContext was called with configuration, but the context type 'MyDBContext' only declares a parameterless constructor的更多相关文章

  1. AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?

    问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...

  2. Code First 启用迁移时出错 "No context type was found in the assembly"

    问题:Code First 启用迁移时找不到上下文DbContext所在的项目. PM> Enable-Migrations No context type was found in the a ...

  3. VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"

    错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...

  4. EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"

    转自:http://www.cnblogs.com/stevenhqq/archive/2013/04/18/3028350.html 以前做项目的时候,没有采用分类库的形式,所以迁移一致非常顺利,没 ...

  5. EntityFramework codefirst Enable-Migrations No context type was found in the assembly “MyApp.Web” error

    Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName &quo ...

  6. No context type was found in the assembly

    如果解决方法中有多个项目存在,记住要在默认项目中选择你需要的项目进行 enable-migrations    add-migration 以及updatebase

  7. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  8. Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8201936 在前文中,我们简要介绍了Andro ...

  9. The logback manual #03# Configuration

    索引 Configuration in logback Automatically configuring logback Automatic configuration with logback-t ...

随机推荐

  1. Atcoder Beginner Contest 166

    VP赛况如下: 前言:感觉这一场题目难度还是比较贴近新生的,我一个codeforces小蓝名一小时居然AK了,F题数据有点水(?)暴力dfs居然都能过... A:A?C 题意:给你字符串,如果字符串是 ...

  2. 你了解C#的协变和逆变吗

    从C# 4.0开始,泛型接口和泛型委托都支持协变和逆变,由于历史原因,数组也支持协变. 里氏替换原则:任何基类可以出现的地方,子类一定可以出现. 协变(out) 协变:即自然的变化,遵循里氏替换原则, ...

  3. 如何用尾插法建立双链表(C语言,非循环)

    如何用尾插法建立双链表 其实本来是想完成汪队给的链表快排的作业,但是我写完建立双链表以后就12点了龟龟,明天还要早起QAQ,我菜死了 一,为啥要有双链表 先说单链表吧单链表长这样 他的一个结点结构就是 ...

  4. React:Lifting State Up

    在学习React的组件的时候,我也好奇组件间需要共享状态或通信的时候,React是如何处理的.在文档的QUICK START的提到Lifting State Up(状态提升),并不是什么新鲜东西.只是 ...

  5. Problem 2232 炉石传说

    Problem 2232 炉石传说 不知道fzu的账号在哪里弄,想要做题的可以到vj上面去做 https://vjudge.net/problem/FZU-2232 #include <iost ...

  6. Python的逻辑结构和函数

    1.Python中的逻辑结构 ①顺序执行 ②选择执行: if...elif...else... 没有switch..case.. ③循环执行: for...in... while... 没有do..w ...

  7. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', ...

  8. 迟早要知道的JS系列之常用数组方法

    常用数组方法 一.不会改变原始数组的方法: 即访问方法,下面的这些方法绝对不会改变调用它们的对象的值,只会返回一个新的数组或者返回一个其它的期望值. 1. concat() ** 语法:** Java ...

  9. 推荐一款复式记账软件——GnuCash

    本文需要搞清楚两个事情,第一,什么是复式记账:第二,GnuCash操作 复式记账,来自百度百科的解释:复式记账法是以资产与权益平衡关系作为记账基础,对于每一笔经济业务,都要以相等的金额在两个或两个以上 ...

  10. linux连个文件都删除不了,什么鬼!

    前言 最近不是redis 6.0 出了吗,官网介绍最新稳定版本是 6.0.3 .于是,我就准备在自己的破小服务器上安装一下.于是,出现了后续的糟心事 (linux 下的文件正常删除不了). 下载了最新 ...