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();
});
}
and part of startup containing ApplicationDbContext
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
It was working well on netcore3.1 but now I can't initialize first migration

Tuhin PaulPosted Feb 21, 2023, 7:50 PM
The error message you're encountering suggests that there may be an issue with the way the ApplicationDbContext is being created or configured during the migration process. One possible cause of this error could be a mismatch between the version of Entity Framework Core that you're using and the version of the .NET runtime that your application is targeting.
To resolve this issue, you may need to update your application's dependencies to match the new version of the .NET runtime that you're using. This can typically be done by updating the "Microsoft.EntityFrameworkCore" and "Microsoft.EntityFrameworkCore.Tools" packages in your project's NuGet package manager to their corresponding versions for .NET 6.0.
You may also need to ensure that your DbContext and any associated models or data structures are compatible with the new version of Entity Framework Core. This can sometimes require modifications to the way your database is configured or the way data is stored.
If you're still experiencing issues after updating your dependencies and ensuring compatibility with Entity Framework Core, you may want to review the specific error message and any relevant documentation to see if there are any additional steps or configurations that need to be made.
Marius VasilePosted Feb 22, 2023, 4:02 PM
It was
changed to
and now is working fine
Marius VasilePosted Feb 22, 2023, 11:42 AM
My app is a razor page asp.net core. used to be net core 3.1 and I try to update to net 6.0. Below line might have a negative effect on running initial migration?
Marius VasilePosted Feb 22, 2023, 4:02 AM
Thank ou Jignesh, my DbContext already follow
Jignesh KumarPosted Feb 22, 2023, 3:58 AM
Hello Marius Vasile,
Please check this one,
https://snede.net/you-dont-need-a-idesigntimedbcontextfactory/
Marius VasilePosted Feb 21, 2023, 7:56 PM
Thank you for your answer, my project file is
All packages updated to latest version for net core 6.0