[SOLVED] Unable to resolve service for type Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger

Issue

I am having difficulties to scaffold an existing MySQL database using EF core.
I have added the required dependencies as mentioned in the oracle doc:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkcore.Tools" Version="6.0.0">

and then, I ran this code in the package manager console:

Scaffold-Dbcontext "server=the.server.ip.address;user=user_name;database=db_name;password=db_password;port=3306" MySql.EntityFrameworkCore -o Data -v

It shows this error:

Unable to resolve service for type
‘Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger`1[Microsoft.EntityFrameworkCore.DbLoggerCategory+Scaffolding]’
while attempting to activate
‘MySql.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory’

Here are the relevant logs in the output window:

Finding design-time services referenced by assembly 'Test2'...
Finding design-time services referenced by assembly 'Test2'...
No referenced design-time services were found.
Finding design-time services for provider 'MySql.EntityFrameworkCore'...
Using design-time services from provider 'MySql.EntityFrameworkCore'.
Finding IDesignTimeServices implementations in assembly 'Test2'...
No design-time services were found.

I don’t know how shall I implement the design time classes and nor did I find any useful links in the web.

Note that I can access and run query on the database using MySQL Workbench.

Solution

I came across the same issue trying to scaffold an existing MySQL database. It looks like the latest version of MySql.EntityFrameworkCore (6.0.0-preview3.1) still uses the EFCore 5.0 libraries and has not been updated to EFCore 6.0.

It also seems Microsoft.EntityFrameworkCore.Diagnostics was last implemented in EFCore 5 and removed in 6.

When I downgraded all the packages to the 5 version level, I was able to run the scaffold command without that error.

Answered By – James Ruth

Answer Checked By – Dawn Plyler (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.