2013-07-23 44 views
4

我已經安裝了Visual Studio和.NET連接器(6.7.4.0)的MySQL。我以前安裝過6.6.5.0。爲什麼它仍然在尋找這個DLL?無法加載'MySql.Data'或它的一個依賴關係。

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: 
+1

你的配置文件('''web。 config'''或''app.config''')指定版本6.6.5.0?如果是這樣,把它撞到6.7.4.0。 – JesseBuesking

+1

它不是 - 但明確地設置它似乎有幫助。我檢查了我的machine.config,它似乎只有.NET 4.0的綁定......很奇怪。 –

回答

6

您可以使用綁定重定向來解決這個錯誤。綁定重定向是一個框架功能,它允許您指示特定程序集的任何請求(由版本/公鑰標記等標識)應該由該程序集的另一個版本提供服務。

所以你應該在和下添加一個節點。在這裏,它應該是這樣的;

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

請注意,公鑰,文化信息可以在exeception找到(在異常在代碼中出現,因爲它是根據你的異常信息上圖)。

P.S. 請記住,如果這些版本之間存在任何實際的接口差異,您最終可能會因爲我們所期望的不匹配而導致出現異常,所以請注意這一點,但通常大多數提供商不會破壞主要版本以外的東西,因此我們不會通常看不到這樣的任何問題:)

+0

這對我有用。 –

+0

偉大的解決方案! – fubo

1

MySQL.Data是外部的DLL。它不是.net框架的一部分。所以你必須將它添加到你的bin或output文件夾中。如果dll存在於GAC中,請將其添加到您的項目引用中。

+0

我一直在本地複製 - 不幸的是沒有合作。 –

0

檢查你的app.config,我想你提到了一個強大的名字mysql.data.dll。

3

插入來自另一篇文章的答案在這裏。問題是machine.config包含對早期版本的MySql DLL(如V6.6.5.0)的引用。這些引用是在安裝MySQL Visual Studio附件(uhg)期間創建的。他們需要重置爲正確版本的dll。

  1. 添加的NuGet引用正確版本的該項目的MySql.Data和MySql.Data.Entity庫。單擊MySQL參考並確定其版本號(例如6.7.4.0)。
  2. 編輯您的machine.config文件* s *,以您的編輯器以管理員身份運行,並用6.7.4.0替換所有MySQL版本6.6.5.0。

請注意,有多個machine.config文件,請確保您觸摸它們全部進行配置。

C:\ WINDOWS \ Microsoft.NET \框架\\配置 和: C:\ WINDOWS \ Microsoft.NET \ Framework64 \\配置

0

我不願意稱這是一個真正的解決方案,但它似乎有其他版本的MySQL的問題,並從舊版.NET連接器安裝程序和MySQL遷移Windows安裝程序。最後,當我重新安裝Windows時,一切都表現得很好。這對許多人來說並不是一個真正的選擇,但是如果你對頭痛感到厭倦,並且它早早地停留在TODO上 - 考慮這樣你就可以離開無羈絆卡

相關問題