Entity Framework: Error: Failed to load configuration from file [...]/appsettings.json; Unable to create a 'DbContext' of type

45 Views Asked by At

I've come across the following error:

Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[FourGameApp.Data.DataContext]' while attempting to activate 'FourGameApp.Data.DataContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

when attempting to run a command dotnet ef migrations add Initial.

The solution with changing the "Copy to output directory" setting to "Always", taken from other posts on SO dud not work, hence this question.

The code for the DataContext class:

using FourGameApp.Entities;
using Microsoft.EntityFrameworkCore;

namespace FourGameApp.Data
{
    public class DataContext : DbContext
    {
        public DataContext(DbContextOptions<DataContext> options) : base(options) { }
        public DbSet<Game> Games { get; set; }  
    }
}
0

There are 0 best solutions below