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
We are trying out EFCore Power Tools for the first time in our .Net5 project with EF Core 5.
The project is able to use migrations and everything related to EF Core works fine, but alas I cannot use EF Core Power Tools since we are always getting the error below (when trying to add DbContext Model diagram via EFCore Power Tools) no matter how much we refactor the code and try different approaches regarding the DbContext DI setup.
The error is this;
System.ArgumentException: Error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'MyDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[MyProject.DataAccess.MyDbContext]' while attempting to activate 'MyProject.DataAccess.MyDbContext'.
Steps to reproduce
Create a custom class derived from DbContext as usual. Register it in the ServiceCollection in Startup.ConfigureServices as recommended;
var connection = new SqlConnection(Configuration.GetConnectionString("DefaultConnection"));
var builder = new DbContextOptionsBuilder<MyDbContext>().UseSqlServer(connection);
services.AddScoped<DbContextOptions<MyDbContext>>(_ => builder.Options);
services.AddDbContext<MyDbContext, MyDbContext>(); // As AddDbContext for design time tooling to find it automatically
We are trying out EFCore Power Tools for the first time in our .Net5 project with EF Core 5.
The project is able to use migrations and everything related to EF Core works fine, but alas I cannot use EF Core Power Tools since we are always getting the error below (when trying to add DbContext Model diagram via EFCore Power Tools) no matter how much we refactor the code and try different approaches regarding the DbContext DI setup.
The error is this;
System.ArgumentException: Error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'MyDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[MyProject.DataAccess.MyDbContext]' while attempting to activate 'MyProject.DataAccess.MyDbContext'.
Steps to reproduce
Create a custom class derived from DbContext as usual. Register it in the ServiceCollection in Startup.ConfigureServices as recommended;
In Program.cs set it all up as you always do;
Further technical details
EF Core Power Tools version: 2.5.406.0
Database engine: SQL Server
Visual Studio version: 2019 - 16.8.3
The text was updated successfully, but these errors were encountered: