C# 无法加载“MySql.Data”或其依赖项之一。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17800725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load 'MySql.Data' or one of it's dependencies.
提问by Vaughan Hilts
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?
我已经为 Visual Studio 和 .NET 连接器 (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:
采纳答案by Haseeb Sd
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;
所以你应该<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>
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).
请注意,publicKeyToken
可以在异常中找到 , 区域性信息(异常发生在您的代码中,因为它基于上面的异常信息)。
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 :)
PS 请记住,如果这些版本之间存在任何实际接口差异,您可能会因我们期望的不匹配而最终得到异常,因此请注意这一点,但通常大多数提供商不会破坏主要版本之外的内容,因此我们不会通常不会看到任何这样的问题:)
回答by Niranjan Reddy
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.
MySQL.Data 是外部 dll。它不是 .net 框架的一部分。所以你必须把它添加到你的 bin 或输出文件夹中。如果 dll 存在于 GAC 中,请将其添加到您的项目引用中。
回答by fengyj
Check your app.config, I think you refered a strong name mysql.data.dll.
检查您的 app.config,我认为您引用了一个强名称 mysql.data.dll。
回答by Greg Grater
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.
在此处插入另一篇文章的答案。问题是machine.config 包含对用于MySql(例如V6.6.5.0)的较早版本dll 的引用。这些引用是在安装 MySQL Visual Studio 插件 (uhg) 期间创建的。它们需要重置为正确版本的 dll。
- Add nugetreferences 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).
- 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.
- 向项目添加对正确版本的 MySql.Data 和 MySql.Data.Entity 库的nuget引用。单击 MySQL 引用并确定它们的版本号(例如 6.7.4.0)。
- 使用以管理员身份运行的编辑器编辑您的 machine.config 文件*s*,并将所有出现的 MySQL 版本 6.6.5.0 替换为 6.7.4.0。
Note, there are multiple machine.config files, make sure you touch them all for your configuration.
请注意,有多个 machine.config 文件,请确保将它们全部用于配置。
C:\Windows\Microsoft.NET\Framework\\Config And: C:\Windows\Microsoft.NET\Framework64\\Config
C:\Windows\Microsoft.NET\Framework\\Config 和:C:\Windows\Microsoft.NET\Framework64\\Config
回答by Vaughan Hilts
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
我会犹豫是否将其称为真正的解决方案,但似乎其他版本的 MySQL 存在问题,并且从旧的 .NET 连接器安装程序和 MySQL for Windows 安装程序迁移。最后,当我重新安装 Windows 时,一切正常。对于许多人来说,这并不是一个真正的选择,但是如果您厌倦了头痛并且迟早会出现在 TODO 上 - 考虑一下这是您的免狱卡