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. Jmeter简单性能测试练习

    项目描述: 被测网站:xqtesting.blog.51cto.com 指标:响应时间以及错误率 场景:线程数20   测试步骤: 测试计划 线程组 http请求 监听器 运行脚本 查看报告 1.添加 ...

  2. tpcc-mysql 试用

    percona 出的一个mysql压力测试工具,至于tpcc的话,是一个衡量事务处理能力的一个值.具体可以看老外对他的定义. http://www.tpc.org/tpcc/results/tpcc_ ...

  3. 「雕爷学编程」Arduino动手做(29)——DS1302时钟模块

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...

  4. Spring+Struts2+Hibernate框架搭建

    SSH框架版本:Struts-2.3.30  +  Spring-4.2.2  +  Hibernate5.2.2 下图是所需要的Jar包: 下面是项目的结构图: 1.web.xml <?xml ...

  5. SMBMS项目-准备工作

    项目搭建准备工作 1.基础准备工作 搭建一-个maven web项目 配置Tomcat 测试项目是否能够跑起来 导入项目中会遇到的jar包 jsp,Servlet,mysq|驱动, jstl, sta ...

  6. mysql 查询获取排名的方法(绝对有效)

    http://blog.csdn.net/k8080880/article/details/11253305 select case when pid=0 then case when @prevTy ...

  7. Hyperledger fabric MSP成员管理

    Hyperledger fabric 1.0 基于 PKI(Public Key Infrastructure)体系,引入了MSP模块(Membership Service Provider): 成员 ...

  8. UVA10480 Sabotage

    题目链接:https://cn.vjudge.net/problem/UVA-10480 知识点: 最小割 题目大意: 求最小割并打印出最小割必须割掉的边. 解题思路: 在跑完 \(sap\) 后的残 ...

  9. POJ1015

    题目链接:http://poj.org/problem?id=1015 大概题意: 法庭要挑选m人陪审团.先随机挑选n个公民,对于每个公民,控辩双方都有各自的“喜好度”p[ ] 和 d[ ],法庭要尽 ...

  10. 工业互联网可视化系统风格的抉择:线框模式之 3D 数据中心机房的实现

    前言 3D 可视化,就是把复杂抽象的数据信息,以合适的视觉元素及视角去呈现,方便系统的展示.维护和管理.而在可视化系统的搭建选择上,所呈现的风格样式效果多种多样,各自所突出的适用场合也不尽相同.对于科 ...