MySQL EF6 'System.Data.EntityClient' is either not registered in the machine

entity-framework-6 mysql vb.net winforms

Question

Ok, I have a working project that was created automatically with the MySQL creator. I can load the forms and add/Up/Del data no issues.

But then when I change the project to class library and try to reference the context it give me the following error.

The ADO.NET provider with invariant name 'MySql.Data.MySqlClient;' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

    System.ArgumentException was unhandled
  HResult=-2147024809
  Message=The ADO.NET provider with invariant name 'System.Data.EntityClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.<GetService>b__0(ArgumentException e, String n)
       at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup)
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
       at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key)
       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
       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.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       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.GetEnumerator()
       at System.Data.Entity.QueryableExtensions.Load(IQueryable source)
       at TvLinksDataEf6.DbWorker.GetSettings() in W:\Projects\TvLinks\TvLinkDataEf6\DBWorker.vb:line 663
       at TvLinksControls.SettingsPanel.LoadSettings() in W:\Projects\TvLinks\TVLinksControls\Panels\SettingsPanel.vb:line 43
       at TvLinks.Main.SettingsMenu_Menu_Click() in W:\Projects\TvLinks\TvLinks\Main.vb:line 212
       at TvLinksControls.MenuButton.Button_Click(Object sender, EventArgs e) in W:\Projects\TvLinks\TVLinksControls\MenuButton.vb:line 20
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at TvLinks.My.MyApplication.Main(String[] Args) in :line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2147024809
       Message=Unable to find the requested .Net Framework Data Provider.  It may not be installed.
       Source=System.Data
       StackTrace:
            at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
            at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup)
       InnerException: 

My Config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <connectionStrings><add name="TvSeriesDB" connectionString="metadata=res://TvLinksDataEf6/TvSeriesDB.csdl|res://TvLinksDataEf6/TvSeriesDB.ssdl|res://TvLinksDataEf6/TvSeriesDB.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;port=3306;server=localhost;user id=root;password=xxx;database=TvLinksMetro&quot;" providerName="System.Data.EntityClient"/></connectionStrings>
</configuration>

Here is my code that is causing the issue

    _localDs = New TvSeriesDB()

    _localDs.settings.Load()

Context:

Partial Public Class TvSeriesDB
    Inherits DbContext

    Public Sub New()
        MyBase.New("TvSeriesDB")
        MyBase.Configuration.LazyLoadingEnabled = False
    End Sub

    Public Sub New(conn As String)
        MyBase.New(conn)
        MyBase.Configuration.LazyLoadingEnabled = False
    End Sub

    Public Sub New(existingConnection As DbConnection, contextOwnsConnection As Boolean)
        MyBase.New(existingConnection, contextOwnsConnection)
    End Sub

    Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
        MyBase.OnModelCreating(modelBuilder)
        modelBuilder.Entity(Of settings)().MapToStoredProcedures()
        modelBuilder.Entity(Of episodes)().MapToStoredProcedures()
        modelBuilder.Entity(Of rssfeeds)().MapToStoredProcedures()
        modelBuilder.Entity(Of tvseries)().MapToStoredProcedures()
    End Sub

    Public Overridable Property episodes() As DbSet(Of episodes)
    Public Overridable Property rssfeeds() As DbSet(Of rssfeeds)
    Public Overridable Property settings() As DbSet(Of settings)
    Public Overridable Property tvseries() As DbSet(Of tvseries)

End Class

Again please note that I am referencing a working project that was created using the create MySQL winforms project.

List of Providers installed on the machine.

Odbc Data Provider .Net Framework Data Provider for Odbc System.Data.Odbc System.Data.Odbc.OdbcFactory, System.Data, Version=4.0.0.0

OleDb Data Provider .Net Framework Data Provider for OleDb System.Data.OleDb System.Data.OleDb.OleDbFactory, System.Data, Version=4.0.0.0

OracleClient Data Provider .Net Framework Data Provider for Oracle System.Data.OracleClient System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=4.0.0.0

SqlClient Data Provider .Net Framework Data Provider for SqlServer System.Data.SqlClient System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0

Microsoft SQL Server Compact Data Provider 4.0 .NET Framework Data Provider for Microsoft SQL Server Compact System.Data.SqlServerCe.4.0 System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0

MySQL Data Provider .Net Framework Data Provider for MySQL MySql.Data.MySqlClient MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0

This is from the Machine.config.

  <system.data>
    <DbProviderFactories>
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    </DbProviderFactories>
  </system.data>

I created another simple solution with 2 winforms projects the first with my Model1 working no errors. Here I am referencing project1 and trying to get the same dataset from my Model1 and again same error.

I created another simple solution with 2 winforms projects the first with my Model1 working no errors. Here I am referencing project1 and trying to get the same dataset from my Model1 and again same error. Also quick update I downloaded all the latest MySQl connector and MySQl for Visual Studio even updated the server to the latest version. After I did that I created this little test solution.

1
1
6/6/2016 12:17:31 AM

Popular Answer

The issue was having multiple Providers defined:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>

Remove the SQLClient including references:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
    </providers>
  </entityFramework>

This only affected when calling from a secondary project like what I was doing.

1
6/24/2016 6:06:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow