2017-10-18 75 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? –