Error occurred while access Microsoft.Extensions.HostingServices. Could not parse JSON file

早过忘川 提交于 2020-03-03 11:55:50

问题


I was trying to create a migration for an MVC ASP.NET Core 3.10 project using Visual Studio 2019. I got two errors:

  1. An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not parse the JSON file.
  2. No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

I assume the first one is the problem, since I already have my DbContext set up as the second one asked.

What I've tried so far:

  1. Rolling back to .NET Core 3.0
  2. Using a name other than "InitialCreate" for the migration.
  3. Installing EntityFrameworkCore.Design, EntityFrameworkCore.SQlite, EntityFrameworkCore.SQlServer, EntityFrameworkCore.Logging.Debug, EntityFrameworkCore.Tools through the NuGet Package Manager
  4. Restarting the computer and trying again
  5. Quadruple-checking that Startup.cs had my DbContext added, and that my DbContext has the constructor set up to take a DbContextOptions in its constructor, passing the input to the base constructor

What should I do about the first error?


回答1:


It turns out that my appsettings.json was missing a closing curly brace. Adding that in fixed the problem.




回答2:


I got a similar issue when following This MVC guide. If anyone is having similar issue, check your appsettings.json file that your are not missing something. (What I did was to copy the code from the tutorial, it broke my code, but when I typed it in, code worked)



来源:https://stackoverflow.com/questions/59346541/error-occurred-while-access-microsoft-extensions-hostingservices-could-not-pars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!