Pomelo.entityframeworkcore.mysql: 5.0.0-alpha.2 Could not load type 'MySql.Data.MySqlClient.MySqlConnection'

Created on 25 Nov 2020  路  4Comments  路  Source: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql

When I installed Pomelo.EntityFrameworkCore.MySql 5.0.0-alpha.2 into my project, I get the following error

TypeLoadException: Could not load type 'MySql.Data.MySqlClient.MySqlConnection' from assembly 'MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92'.

If I remove it, I get not errors.

I manually downloaded the project from Github and added it to a new folder into my solution called "Pomelo". Then added the existing project EfCore.MySql into my solution. But for some reason I can't compile it.

image

My solution is based on .Net Core 5 framework I am not sure if there is a compatibility issue.

Any help is greatly appreciated.

type-question

All 4 comments

Regarding the usage of the Pomelo.EFCore package:

As can be seen on our main page under Dependencies, 5.0.0-alpha.2 needs a minimum MySqlConnector version of 1.1.0.

Also, MySqlConnector changed its namespace since version 1.0.0 from MySql.Data.MySqlClient to MySqlConnector.

I would recommend you check your PackageReference tags first for the correct version of MySqlConnector. Then search in all files of your project for MySql.Data.MySqlClient (and after that maybe even for MySql.Data) and replace it with MySqlConnector.

@lauxjpn
We are having a similar issue with 5.0.0-alpha.2 in .Net Core 5.0.
Trying to run this line after the update:
Users user = await _ctfdReadContext.Users.Include(u => u.Unlocks).Include(s => s.Submissions). Where(u => u.Name.ToLower() == userName.ToLower()).FirstOrDefaultAsync();

produces this error:
2020-12-22 20:18:07.074 -08:00 [ERR] An unhandled exception has occurred while executing the request. System.TypeLoadException: Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.

We are using the latest package of MySqlConnector:

`<PackageReference Include="AWSSDK.Core" Version="3.5.1.55" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.101" />
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.5.0.55" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.5.1.26" />
<PackageReference Include="AWSSDK.SQS" Version="3.5.1.4" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
<PackageReference Include="Braintree" Version="5.2.0" />
<PackageReference Include="CsvHelper" Version="18.0.0" />
<PackageReference Include="libphonenumber-csharp" Version="8.12.15" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebHooks.Receivers" Version="1.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.1" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.22" />
<PackageReference Include="MySqlConnector" Version="1.2.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="TimeZoneNames" Version="4.1.0" />`

That exception is from MySql.Data.EntityFrameworkCore not Pomelo, check your AddDbContext in Startup. Also see Entity framework core and MySql.Data in the same project.

@bferguson-sentek While this is the wrong repository for Oracle's MySQL EF Core provider, the issue is that you are trying to use an EF Core 3.x provider with EF Core 5.0, which does not work. As far as I know, Oracle has currently no EF Core 5.0 support.

Feel free to use our latest Pomelo prerelease for all your calls (currently 5.0.0-alpha.2, as you have already referenced in your project), which is EF Core 5.0 compatible. You will need to use UseMySql() instead of UseMySQL() (casing).

Was this page helpful?
0 / 5 - 0 ratings