16

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?

Tespy
  • 971
  • 2
  • 9
  • 18

9 Answers9

39

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

Tespy
  • 971
  • 2
  • 9
  • 18
19

Luckily I came across this thread and I'm kicking myself for not taking the error message literally.
There were plenty of hints... enter image description here


The one reason the error doesn't just **POP** out is because its just a **warning**.

You can change this behavior in Visual Studio
Goto Tools->Options.
Click Text Editor->JSON->Advanced.
Under Validation change Show errors as warnings to False

enter image description here
You still get the same message on the console.. But this change makes the error a little more dramatic that there is an issue. enter image description here

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
5

The issue for me is that I had a typo in my user secrets secrets.json file. I was missing a comma after a property value.

For reference, you can edit user secrets in VS2019 by right-clicking on a .NET Core project and selecting Manage User Secrets.

joelfp
  • 131
  • 3
  • 8
4

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)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ian Bílek
  • 41
  • 1
2

I had an issue in appsettings.json. In JSON, I forgot to add comma after AllowedHosts. As soon as I fixed that it worked.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
2

This error could be due to syntax error. In my case, I missed a comma(,) after "AllowedHosts": "*" in appsettings.json file.

Comma missing in the screenshot enter image description here

After adding the comma, Build succeeded. Screenshot added below for reference.

Build Succeeded enter image description here

Dave
  • 3,073
  • 7
  • 20
  • 33
0

I got this error when I created appsettings.Development.json on vscode and didn't save it. The compiler didn't know which appsettings file to use. It was resolved when I saved the appsettings.Development.json file.

0

Strange ; i had the same problem and same warnings but all settings were fine .

i just Cut all text in Appsettings and pasted it again then got Fixed !

0

i was missing a backward slash in my connectionstring in the appsettings.json file.