"No DbContext found in assembly" after migrating to EF 2(.1) and ASP.Net Identity Core 2(.1)

See original GitHub issue

Describe 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
oswaldozapatacommented, Apr 5, 2020

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

1reaction
ajcvickerscommented, Sep 25, 2018

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration: No DbContext was found in assembly
In the Package Manager Console select the project where the DbContext is defined and run the command add-migration initial .
Read more >
[Solved]-Migration: No DbContext was found in assembly-C#
You have to specify the project name where the DbContext is located. So just right on the Nugget PM Console, type: Add-Migration MigrationName...
Read more >
No dbcontext was found in assembly ...
I want to create Add-Migration eNtsaMigration, i kept receiving this message each time. I have installed all the required packages on my project ......
Read more >
No DbContext was found in assembly. Ensure you using ...
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration ...
Read more >
Add-Migration CreateIdentitySchema - Microsoft Q&A
No DbContext named 'WebApplication1Context.cs' was found. ASP.NET Core.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found