2017-10-18 78 views
4

所以我的解決方案編譯,但是當我運行它時,我在運行.NET 4.6.1的類庫中出現錯誤。彙編版本不匹配? (.Net Core 2.0與.NET標準2類庫)

System.TypeLoadException: 'Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

有什麼建議嗎?

編輯:

完全錯誤:

$exception {System.TypeLoadException: Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func 3 handleFailedLookup) at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetServices(Type type, Object key) at System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 valueFactory) at System.Linq.Enumerable.SelectManySingleSelectorIterator 2.MoveNext() at System.Linq.Enumerable.ConcatIterator 1.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator 2.MoveNext() at System.Linq.Enumerable.ConcatIterator 1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__32 1.MoveNext() at System.Collections.Generic.List 1.AddEnumerable(IEnumerable 1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1 source) at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.Lock() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() at System.Lazy 1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy 1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy 1.CreateValue() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration() at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) at X.Y.ConfigurationModule.ConfigurationContainer..ctor(String nameOrConnectionString)} System.TypeLoadException

+1

您是否引用了System.Data.Common.DbProviderFactories? – 2017-10-18 10:54:50

回答

1

你看這類型的錯誤,當你正在使用的組件與組裝參考不同。

在這種情況下你是因爲使用第3版第一個使用2

enter image description here

Version Problem

其他請做這些檢查看到這個錯誤

1:Open references right click on System.Data.Common.DbProviderFactories assembly and check its version

2:Now open you package config or app config file and check the version of that assembly there.

解決方案

如果版本衝突請安裝

https://www.nuget.org/packages/System.Data.Common/

庫然後進入bin文件夾刪除「System.Data.Common.DbProviderFactories」 DLL也從引用刪除您的項目,然後點擊添加參考轉到包文件夾,因爲您下載的最新庫進入此文件夾,所以只需添加參考。 現在右鍵單擊此程序集並複製版本名稱,然後將該版本粘貼到您的appconfig或程序包配置文件中。

+0

感謝您的回覆。我沒有明確引用任何程序集。我試圖從Nuget獲取System.Data.Common,但嘗試nuget包中的不同版本沒有幫助。這似乎不管我嘗試錯誤消息保持不變。它指的是版本4.0.0.0,它從來不是正在使用的版本。錯誤可能是System.Data而不是System.Data.Common,那麼4.0.0.0會更有意義。 –

+0

那麼你還面臨着同樣的問題? – 2017-10-18 11:53:32

+0

是的,問題依然存在。錯誤說:「從彙編System.Data」所以也許從來沒有任何錯誤的System.Data.Common? –