Bug: Could not load type 'MySql.Data.MySqlClient.MySqlDbType
phungxuanvuong opened this issue · 2 comments
phungxuanvuong commented
When I try run Portal project, how can I fix it.
Unhandled exception. System.TypeLoadException: Could not load type 'MySql.Data.MySqlClient.MySqlDbType' from assembly 'MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92'.
at Quartz.AspNetCore.MySqlConnector.MySqlConnectorDbMetadata..ctor() reServicesWithContainerConfiguration|0(IServiceCollection services).AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)StartupServicesFilterPip
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)lection services)serviceCollecti
at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()gateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__Configur
at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at DotnetSpider.Portal.Program.Main(String[] args) in F:\learn\crawer\DotnetSpider\src\DotnetSpider.Portal\Program.cs:line 36
When I updated Mysql to 1.0.0, the error was resove. But I get another error:
A relational store has been configured without specifying either the DbConnection or connection string to use
JmlSaul commented
seems the problem is with Quartz.AspNetCore.MySqlConnector
, the project is targeting MySqlConnector 0.61.0
, where the type MySql.Data.MySqlClient.MySqlDbType
is existed. in the current version of MySqlConnector
it is removed.
JmlSaul commented
temporarily copy these two class to your portal project, and remove reference to Quartz.AspNetCore.MySqlConnector
may fix the problem. or the owner updates Quartz.AspNetCore.MySqlConnector
.
public static class ServiceCollectionExtensions
{
public static QuartzOptionsBuilder UseMySqlConnector2(this QuartzOptionsBuilder builder, string connectString, string serializerType = "binary", string tablePrefix = "QRTZ_")
{
builder.UseMySql(connectString, serializerType, tablePrefix);
builder.Properties.Set("quartz.dataSource.myDs.provider", "MySqlConnector");
MySqlConnectorDbMetadata mySqlConnectorDbMetadata = new MySqlConnectorDbMetadata
{
ParameterDbTypePropertyName = "MySqlDbType",
DbBinaryTypeName = "Blob"
};
mySqlConnectorDbMetadata.Init();
DbProvider.RegisterDbMetadata("MySqlConnector", mySqlConnectorDbMetadata);
return builder;
}
}
public class MySqlConnectorDbMetadata : DbMetadata
{
private readonly Type _parameterDbType;
private readonly Type _connectionType;
private readonly Type _commandType;
private readonly Type _parameterType;
private readonly Type _exceptionType;
public override string ProductName => "MySQL, MySQL provider";
public override string ParameterNamePrefix => "?";
public override Type ConnectionType => _connectionType;
public override Type CommandType => _commandType;
public override Type ParameterDbType => _parameterDbType;
public override Type ParameterType => _parameterType;
public override Type ExceptionType => _exceptionType;
public override bool BindByName => true;
public MySqlConnectorDbMetadata()
{
_parameterDbType = typeof(MySqlDbType);
_connectionType = typeof(MySqlConnection);
_commandType = typeof(MySqlCommand);
_parameterType = typeof(MySqlParameter);
_exceptionType = typeof(MySqlException);
}
}