Unable to create an object of type '[DBContext's Name]'. For the different patterns supported at design time

asp.net asp.net-mvc ef-migrations entity-framework entity-framework-core

Question

I'm following one of Mosh Hamedani Course on ASP.NET MVC in Udemy.

I came across one error while designing my Database using code-first (Entity Framework).

At first, I got the error of " No DbContext was found in assembly". After resolving this problem another one surged from nowhere.

The image below will show you the error found while adding a migration. I've already searched for the same error but in vain. I'm struggling for the past two hours but nothing is solved till now.

Please, someone, help me. Thanks

unable to create an object of type 'Vidly_Context'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

1
2
5/27/2019 9:41:52 AM

Popular Answer

I ran into this issue when EF Core code first migrations in a .NET Core 3 solution that contains both an MVC project and a Blazor project.

If I have the solution's startup project set to the Blazor project I get the error when using add-migration, but I don't if I have the startup project set to the MVC project.

From reading the documentation page linked to by the error message and comparing the code in the startup.cs files for both projects I'm not sure why that would be, but temporarily switching the startup project to the MVC project fixes it for me.

4
5/27/2019 9:45:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow