"No DbContext found in assembly" after migrating to EF 2(.1) and ASP.Net Identity Core 2(.1)
See original GitHub issueDescribe what is not working as expected.
I’m working on a Mac with Visual Studio for Mac (and VSCode if needed).
I try to update my existing .Net Core 1.1, EF Core 1.1, ASP.Net MVC Core 1.1 and ASP.Net Identity Core 1.1 to all the latest versions. After applying lots of tutorials I’m stuck. I decided to restart the MVC app / assembly from scratch by using
dotnet new webapp --auth individual
This template worked. I then tried to move my cheese over. Especially removing the existing migration and database and using my own ApplicationDbContext stored in my “Common” assembly. It introduces a new IdentityUser with IdentityRoles on default.
Now I’m stuck again as I always get the following error messages:
$ dotnet ef migrations add initial
No DbContext was found in assembly 'Tauchbolde.Web'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
$ dotnet ef dbcontext info
No DbContext was found in assembly 'Tauchbolde.Web'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
$ dotnet ef dbcontext list
No DbContext was found.
I have absolutely no clue anymore what this thing is missing. Any help would be really appreciated.
Steps to reproduce
You can reproduce by cloning my repo from GitHub and try to add an initial migration:
dotnet ef migrations add initial
Further technical details
EF Core version: 2.1 (2.1.3) Database Provider: Previously SqlServer but now on SqlLite Operating system: macOs High Sierra IDE: latest Visual Studio for Mac / Latest VS Code
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Related StackOverflow Question
I got resolved my issue by using the command this way: cd to your startup project root folder, from there execute all the commands MyProject.MigrationApp/> dotnet ef dbcontext list --project …/MyProject.EFCoreSqlServer
MyProject.MigrationApp, this is my startup project MyProject.EFCoreSqlServer, this is the project that contains the db context definitions.
Now in the same way you can run all the other commands
MyProject.MigrationApp/> dotnet ef database update --project …/MyProject.EFCoreSqlServer
@mduu Looks like the DbContext is not in the main project. The code you posted doesn’t build for me, so I haven’t been able to try it, but it looks like you need to specify the project on the command line as described here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#using-the-tools