An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Failed to load configuration from file 'C:\Users\SHIVRAJ\source\repos\CRUDEF\appsettings.json'.
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[CRUDEF.SchoolContext]' while attempting to activate 'CRUDEF.SchoolContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see
Loading
Jayraj ChhayaPosted Jan 28, 2025, 10:37 AM
Hi SHIVRAJ GOPCHADE,
The error you are experiencing typically arises from issues with the configuration file or the dependency injection setup for your
DbContext. Here are a few steps to troubleshoot and resolve the issue:Check
appsettings.json: Ensure that theappsettings.jsonfile exists at the specified path and is correctly formatted. A missing or malformed file can lead to configuration loading failures.Configure Services: In your
Startup.cs, ensure that you have properly configured theDbContextin theConfigureServicesmethod. For example:appsettings.jsonis correct and points to a valid database server.By following these steps, you should be able to resolve the issue and successfully create your database. If the problem persists, consider checking for additional details in the error message or logs for further insights.
Rajendra TaradalePosted Jan 28, 2025, 10:33 AM
Please check the package reference and version, dependency injections and connection string details
public void ConfigureServices(IServiceCollection services)(options => options.UseSqlServer(Configuration.GetConnectionString("")));
{
services.AddDbContext
}
Next -
public class SchoolContext : DbContext options) : base(options) { }
{
public SchoolContext(DbContextOptions
}