EDIT: SOLVED. Rider unable to perform dotnet ef migrations add xyz. "Unable to create a 'DbContext' of type ''. " Works perfect in VS 2022

EDIT- Solved, see solution in the first comment. 


I'm new to Rider so trying to figure this out. I have a Dotnet 8 Blazor Webapp that was working great till last week. However, now when I update the domain model and try and do a DB update using code-first migrations, I get this error

“Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[SpaceLab.Infrastructure.Data.ApplicationDbContext]' ”

However, when I open the solution in Visual Studio 2022, all the migration and update commands work as expected. The application also runs just fine, DB usage is normal for all CRUD applications. So it's not a misconfiguration issue, just something to do with Rider?

I am currently coding in Rider but switching to VS 2022 to perform the migrations. How do I fix this?




 Figured it out. THis is not a Rider specific issue. All I need to do is specify the Startup project (which is a different project in my solution, the WebUI is different from the Infrastructure; I'm following clean architechture. )

command is

dotnet ef migrations add MigrationNew --startup-project ../<STARTUP PROJECT>

then everything works as before. 


Thanks for your comments, Rider also has EF Core UI implemented, it is worth trying it.


Please sign in to leave a comment.