Could not load 'MySql.Data' or one of it's dependencies.


I've installed the MySQL for Visual Studio and the .NET Connector ( I previous had the installed. Why is it still looking for this DLL?

System.IO.FileLoadException was unhandled
  Message=Could not load file or assembly 'MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  FileName=MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d
  FusionLog==== Pre-bind state information ===
LOG: User = Vaughan-PC\Vaughan Hilts
LOG: DisplayName = MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d
LOG: Appbase = file:///C:/Users/Vaughan Hilts/Documents/GitHub/blastersgame/BlastersOnline/LobbyServer/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Vaughan Hilts\Documents\GitHub\blastersgame\BlastersOnline\LobbyServer\bin\Debug\LobbyServer.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: MySql.Data, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d
LOG: Attempting download of new URL file:///C:/Users/Vaughan Hilts/Documents/GitHub/blastersgame/BlastersOnline/LobbyServer/bin/Debug/MySql.Data.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
       at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
       at System.Type.GetType(String typeName)
       at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
       at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
       at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(String providerInvariantName)
       at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
       at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
       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.FirstOrDefault[TSource](IQueryable`1 source)
       at LobbyServer.Lobby.Main(String[] args) in c:\Users\Vaughan Hilts\Documents\GitHub\blastersgame\BlastersOnline\LobbyServer\Lobby.cs:line 64
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       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()
asked on Stack Overflow Jul 23, 2013 by Vaughan Hilts

5 Answers


You can use a binding redirect to solve this error. Binding redirect is a framework feature which allows you to indicate that any requests for a specific assembly (identified by version/public key token etc) should be serviced by another version of that assembly.

So you should add a <dependentAssembly> node under <runtime> and <assemblyBinding>. Here, it is how it should look like;

   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
       <bindingRedirect oldVersion="" newVersion="" />

Please note that the publicKeyToken, culture information can be found in the exeception (where the exception occurs in your code, as it's based on your exception info above).

P.S. Keep in mind if there are any actual interface differences between those versions you may end up getting exceptions due to a mismatch in what we expect so watch out for that, but usually most providers don't break things outside of major versions so we don't usually see any issues like this :)

answered on Stack Overflow Dec 12, 2013 by Haseeb Sd • edited Mar 18, 2019 by Kev

Plugging in an answer from another post here. The problem was the machine.config contained references to earlier versions of the dll's for MySql (e.g. V6.6.5.0). These references were created during the install of the MySQL Visual Studio add on (uhg). They need to be reset to the correct version of the dlls.

  1. Add nuget references to the MySql.Data and MySql.Data.Entity libraries of the correct version to the project. Click on the MySQL references and determine their version number (e.g.
  2. Edit your machine.config file*s* with your editor run as administrator, and replace all occurences of MySQL version by

Note, there are multiple machine.config files, make sure you touch them all for your configuration.

C:\Windows\Microsoft.NET\Framework\\Config And: C:\Windows\Microsoft.NET\Framework64\\Config

answered on Stack Overflow Oct 29, 2013 by Greg Grater

MySQL.Data is external dll. It is not part of .net framework. So you have to add it in your bin or output folder. if the dll is present in GAC, add it in your project references.

answered on Stack Overflow Jul 23, 2013 by Niranjan Reddy

Check your app.config, I think you refered a strong name

answered on Stack Overflow Jul 23, 2013 by fengyj

I'd be hesistant to call this a real solution but it seems like there was issues with other versions of MySQL and migrating from the legacy .NET connector installer and the MySQL for Windows installer. In the end, when I did a reinstall of Windows everything behaved. This isn't really an option for many but if you're sick of headaches and it's on the TODO for sooner rather than later - consider this your get out of jail free card

answered on Stack Overflow Dec 18, 2013 by Vaughan Hilts

User contributions licensed under CC BY-SA 3.0