Bug #103909 Unable to determine the provider name for provider factory of type 'MySql.Data.M
Submitted: 4 Jun 2021 6:57 Modified: 30 Oct 2021 11:51
Reporter: goobeer goobeer Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.21.0 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: EF6.4.4, Mysql.Data.8.0.21

[4 Jun 2021 6:57] goobeer goobeer
Description:
when use mysql.data.dll with entityframework,that throws an exception.

System.NotSupportedException
  HResult=0x80131515
  Message=Unable to determine the provider name for provider factory of type 'MySql.Data.MySqlClient.MySqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderInvariantName(DbProviderFactory factory)
   at System.Data.Entity.Infrastructure.DependencyResolution.DefaultInvariantNameResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass4_0.<GetService>b__0(Tuple`2 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass5_0.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass5_0.<GetService>b__0(IDbDependencyResolver r)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
   at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection)
   at System.Data.Entity.Internal.InternalConnection.get_ProviderName()
   at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()
   at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
   at Common.EntityFramework.BaseRepository`2.Where(Expression`1 predicate) in D:\workcode\oscarcore\Common.EntityFramework\BaseRepository.cs:line 220
   at Customer.Service.Controllers.CustomerController.GetCustomerNameById(Int64 id) in D:\workcode\oscarcore\Customer.Service\Controllers\CustomerController.cs:line 207
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

How to repeat:
throw exception condtion:

public class CustomerEntities : DbContext{
//this conditon will throw an exception 
//System.NotSupportedException
  HResult=0x80131515
  Message=Unable to determine the provider name for provider factory of type 'MySql.Data.MySqlClient.MySqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
}

[DbConfigurationType(typeof(MySql.Data.EntityFramework.MySqlEFConfiguration))]
public class CustomerEntities : DbContext{

//however,use DbConfigurationTypeAttribute to decorate the DbContext,everything is ok !
}

Suggested fix:
whether can remove DbConfigurationTypeAttribute ?
[4 Jun 2021 8:10] goobeer goobeer
the reason is that
mysql.data doesn't contain mysql.data.entityframework
by you code is

private FieldInfo MySqlDbProviderServicesInstance
	{
		get
		{
			if (_mySqlDbProviderServicesInstance == null)
			{
				string fullName = Assembly.GetExecutingAssembly().FullName;
				string text = fullName.Replace("MySql.Data", "MySql.Data.EntityFramework");
				string text2 = fullName.Replace("MySql.Data", "MySql.Data.Entity.EF5");
				fullName = "MySql.Data.MySqlClient.MySqlProviderServices, " + text2;
				Type type = Type.GetType(fullName, throwOnError: false);
				if (type == null)
				{
					fullName = "MySql.Data.MySqlClient.MySqlProviderServices, " + text;
					type = Type.GetType(fullName, throwOnError: false);
					if (type == null)
					{
						throw new DllNotFoundException(fullName);
					}
				}
				_mySqlDbProviderServicesInstance = type.GetField("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
			}
			return _mySqlDbProviderServicesInstance;
		}
	}
[30 Sep 2021 11:51] MySQL Verification Team
Hello,

Thank you for the bug report.
Could you please provide repeatable test case (sample project, etc. - please make it as private if you prefer) to confirm this issue at our end?

Regards,
Ashwini Patil
[1 Nov 2021 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".