Marius Vasile

Marius Vasile

  • 552
  • 1.9k
  • 145.9k

asp.net core update to net 6.0 error on initial migration

Feb 21 2023 7:13 PM

I am trying to update my app from netcore3.1 to net 6.0 but on initial migration I have following error

Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see .....

I haven't change startup.cs and program.cs, see below

public class Program
{
    public static void Main(string[] args)
    {
        var host = CreateWebHostBuilder(args).Build();

        host.Run();

    }

    public static IHostBuilder CreateWebHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

and part of startup containing ApplicationDbContext

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

It was working well on netcore3.1 but now I can't initialize first migration


Answers (6)