Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using EF Core Power Tools #604

Open
hddhagai opened this issue Sep 23, 2023 · 2 comments
Open

Error when using EF Core Power Tools #604

hddhagai opened this issue Sep 23, 2023 · 2 comments

Comments

@hddhagai
Copy link

hddhagai commented Sep 23, 2023

  • .NET SDK Version: .net 6

Always keep getting this error when using EF Core Power Tools.

System.InvalidOperationException: Error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'AppDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions1[Ex.Infrastructure.Data.AppDbContext]' while attempting to activate 'Ex.Infrastructure.Data.AppDbContext'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Modelling.EfCoreModelBuilder.BuildResult(String outputPath, String startupOutputPath, Boolean generateDdl) in C:\Code\EFCorePowerTools\src\GUI\efpt30.core\EFCoreModelBuilder.cs:line 41
at Modelling.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt30.core\Program.cs:line 56

at async Task EFCorePowerTools.Handlers.ModelAnalyzerHandler.GenerateAsync(string outputPath, Project project, GenerationType generationType)

I have Multiple start up projects. Have tried with just the web as the start up project still get the error. Is there something that I am missing? Am new to Clean Architecture

@fbjerggaard
Copy link

Did you change the database provider?
I encountered this when I switched to npgsql, however setting the connection string to the correct format fixed this error.

@yogyogi
Copy link

yogyogi commented Feb 16, 2024

This is how I run the repo:

  1. Only the "Web" project is the startup project.
  2. Also delete the database file given inside the "Web" project. This is because once you run the app the database will be automatically created so you don't have to run the migrations.

Also to tell that I have added Identity on this repo then done the migrations, it worked for me. The description of this repo contains the migration command which I ran. The migration command has to run from the directory of the "web" project because here you have the project file of the "web" project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants