You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My repo at https://github.com/suugbut/CodegenBug provides some batch files to generate the solution and many more. Here I just pasted the problem description from it.
To illustrate the problem, I make 4 projects as follows:
Building project ...
Finding the generator 'minimalapi'...
Running the generator 'minimalapi'...
Minimal hosting scenario!
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'User'
Unable to create a 'DbContext' of type 'Context.AppDbContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[ContUnable to create a 'DbContext' of type 'Context.AppDbContext'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Context.AppDbContext]' while attempting to activate 'Context.AppDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 StackTrace:
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.DbContextActivator.CreateInstance(Type contextType, Assembly startupAssembly, IOperationReportHandler reportHandler, String[] args)
at Microsoft.EntityFrameworkCore.Design.DbContextActivator.CreateInstance(Type contextType, Assembly startupAssembly, IOperationReportHandler reportHandler)
at Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.EntityFrameworkModelProcessor.TryCreateContextUsingAppCode(Type dbContextType, Type startupType)
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Context.AppDbContext]' while attempting to activate 'Context.AppDbContext'. StackTrace:
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass20_5.<FindContextTypes>b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Context.AppDbContext]' while attempting to activate 'Context.AppDbContext'.
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:20.53
The text was updated successfully, but these errors were encountered:
My repo at https://github.com/suugbut/CodegenBug provides some batch files to generate the solution and many more. Here I just pasted the problem description from it.
To illustrate the problem, I make 4 projects as follows:
Model
project with one entity modelUser.cs
Context
project with one database contextAppDbContext.cs
MigrationForSqlite
project with a trivial classEmpty.cs
This project is used to keep migration files generated by ef tool for specific db provider (in this case for sqlite).
Api
project withProgram.cs
I successfully did the following:
dotnet ef migrations add Initializaiton -s Api -p MigrationForSqlite
dotnet ef database update -s Api
dotnet run --project Api --launch-profile https
https://localhost:7255
that producesHello World
After shutting the server down, I attempted to scaffold endpoints for
User
model with the following batch file but I failed.The error messages are:
The text was updated successfully, but these errors were encountered: