汇编版本不匹配?(.Net Core 2.0与.NET Standard 2类库)

Lar*_*rén 5 .net c# asp.net

所以我的解决方案编译但是当我运行它时,我在运行.NET 4.6.1的类库中遇到错误.

System.TypeLoadException:'无法从程序集'System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.Data.Common.DbProviderFactories'.

有什么建议?

编辑:

完成错误:

$ exception {System.TypeLoadException:无法从程序集'System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.Data.Common.DbProviderFactories'.在System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(系统类型,对象键,Func 3 handleFailedLookup) at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetServices(Type type, Object key) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey键,Func 2 valueFactory) at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext())System.Linq.Enumerable.ConcatIterator 1.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()at System .Linq.Enumerable.ConcatIterator 1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__321.MoveNext()at System.Collections.Generic.List 1.AddEnumerable(IEnumerable1 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.Lazy1.ViaFactory(LazyThreadSafetyMode mode)at System.Lazy 1.CreateValue 1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy( )System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration()at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection,DbCompiledModel model)at XYConfigurationModule.ConfigurationContainer..ctor(String nameOrConnectionString)} System.TypeLoadException

小智 1

当您使用的程序集与参考程序集不同时,您会看到此类错误。

例子

在这种情况下,您会看到此错误,因为第一个使用版本 3,其他使用版本 2

在此输入图像描述

版本问题

请做这些检查

1:打开引用右键单击System.Data.Common.DbProviderFactories程序集并检查其版本

2:现在打开包配置或应用程序配置文件并检查该程序集的版本。

解决方案

如果版本冲突,请安装该库

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

然后转到 bin 文件夹,删除“System.Data.Common.DbProviderFactories” dll,并将其从项目的引用中删除,然后单击“添加引用”转到包文件夹,因为您下载的最新库位于此文件夹中,因此只需添加引用即可。现在右键单击此程序集并复制版本名称并将该版本粘贴到您的 appconfig 或包配置文件中。