Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

System.IO.FileLoadException was unhandled
  HResult=-2146234304
  Message=Could not load file or assembly 'MySql.Data, Version=6.6.5.0, 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)
  Source=mscorlib
  FileName=MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
  FusionLog==== Pre-bind state information ===
LOG: User = Vaughan-PC\Vaughan Hilts
LOG: DisplayName = MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Vaughan Hilts/Documents/GitHub/blastersgame/BlastersOnline/LobbyServer/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Data, Version=4.0.0.0, 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=6.6.5.0, 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.

  StackTrace:
       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()
  InnerException: 
like image 512
Vaughan Hilts Avatar asked Jul 23 '13 02:07

Vaughan Hilts


2 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;

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

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 :)

like image 78
Haseeb Sd Avatar answered Oct 31 '22 00:10

Haseeb Sd


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. 6.7.4.0).
  2. Edit your machine.config file*s* with your editor run as administrator, and replace all occurences of MySQL version 6.6.5.0 by 6.7.4.0.

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

like image 2
Greg Grater Avatar answered Oct 31 '22 01:10

Greg Grater