Unable to resolve service for type ‘Microsoft… ..TypeMappingSource Dependencies’

At the time of this post, there seems to be a bug in Mysql.EntityFrameworkCore using EF 6.0. It’s being tracked on the MySQL bug tracker where I’ve also left a comment.

But if you are getting the error quoted below, you’re probably hitting this bug.

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

The fix is apparently simple. Add this to your application

public class MysqlEntityFrameworkDesignTimeServices : IDesignTimeServices
    public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
        new EntityFrameworkRelationalDesignServicesBuilder(serviceCollection)

The issue seems to lie with TryAddCoreServices(). Microsoft appears to have introduced this in .NET6, and it seems to register some required services including TypeMappingSourceDependencies but it wasn’t implemented in Mysql.EntityFrameworkCore – hence the bug.

The source tests still pass, so I guess the tests don’t cover the design time services (I didn’t dig into them in detail).

I’ve not had any feedback yet from anybody to say this did or didn’t work, but it does work for me. Hopefully, Oracle will respond to the bug soon.