Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies'

06 Feb 2022 - David Baker

Tags: dotnet code

I just had the rare experience of googling a programming error and only getting 1 result, which also happened to be in a foreign language:

Unable to resolve service for type ‘Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies’ while attempting to activate ‘MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource’

Google

It’s especially weird because I’m doing something super basic. I’m creating a new EntityFramework app in .NET 6 and trying to create my first migrations with dotnet ef migrations add InitialCreate.

Since it appears to be something related to MySql.Data.EntityFrameworkCore I new I had the option of using a different MySQL EF provider with Pomelo.EntityFrameworkCore.MySql. I gave it a shot and it worked. So if you get this error, try switching to Pomelo.

dotnet remove package MySql.EntityFrameworkCore
dotnet add package Pomelo.EntityFrameworkCore.MySql

Don’t forget to update your Startup.cs. Then:

dotnet ef migrations add InitialCreate

Working!