我已经为Visual Studio和.NET Connector(6.7.4.0)安装了MySQL。我之前安装了6.6.5.0。为什么还在寻找这个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:
答案 0 :(得分:9)
您可以使用绑定重定向来解决此错误。绑定重定向是一个框架功能,它允许您指示对该特定程序集的任何请求(由版本/公钥标记等标识)应该由该程序集的另一个版本提供服务。
因此,您应在<dependentAssembly>
和<runtime>
下添加<assemblyBinding>
节点。在这里,它应该是这样的;
<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>
请注意,publicKeyToken
文化信息可以在exeception中找到(代码中出现异常,因为它基于您上面的异常信息)。
P.S。 请记住,如果这些版本之间存在任何实际的界面差异,您可能会因为我们所期望的不匹配而最终获得例外,但通常大多数提供商都不会破坏主要版本以外的内容,因此我们不会通常会看到这样的问题:)
答案 1 :(得分:2)
在这里插入另一篇文章的答案。问题是machine.config包含对MySql的早期版本的dll的引用(例如V6.6.5.0)。这些引用是在安装MySQL Visual Studio add(uhg)期间创建的。他们需要重置为正确版本的dll。
请注意,有多个machine.config文件,请确保为您的配置触摸它们。
C:\的Windows \ Microsoft.NET \框架\\配置 和: C:\的Windows \ Microsoft.NET \ Framework64 \\配置
答案 2 :(得分:1)
MySQL.Data是外部dll。它不是.net框架的一部分。所以你必须将它添加到bin或output文件夹中。如果dll存在于GAC中,请将其添加到项目引用中。
答案 3 :(得分:0)
检查你的app.config,我认为你提到了一个强名称mysql.data.dll。
答案 4 :(得分:0)
我很想称这是一个真正的解决方案,但似乎其他版本的MySQL存在问题,并从旧的.NET连接器安装程序和MySQL for Windows安装程序迁移。最后,当我重新安装Windows时,一切都表现得很好。对于很多人来说,这不是一个真正的选择,但是如果你厌倦了头痛,而且很快就会出现在TODO上 - 考虑一下这是你从监狱免费卡出来的