C# 如何解决:无法加载或组装Npgsql或其依赖项之一

C# 如何解决:无法加载或组装Npgsql或其依赖项之一,c#,postgresql,entity-framework-6,C#,Postgresql,Entity Framework 6,我正在尝试使用C#创建API,但由于必须启用迁移,因此出现以下错误: The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. 我正在使用EntityFramework 6.2.0和EntityFr

我正在尝试使用C#创建API,但由于必须启用迁移,因此出现以下错误:

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
我正在使用EntityFramework 6.2.0和EntityFramework.Npgsql 3.2.1.1,并在将以下代码段插入Web.config之后:


现在我遇到了这个问题:

正在检查上下文是否以现有数据库为目标。。。
System.IO.FileLoadException:无法加载文件或程序集“Npgsql,版本=4.1.1.0,区域性=中性,PublicKeyToken=5d8b90d52f46fda7”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)
文件名:“Npgsql,版本=4.1.1.0,区域性=中性,PublicKeyToken=5d8b90d52f46fda7”-->System.IO.FileLoadException:无法加载文件或程序集“Npgsql,区域性=中性,PublicKeyToken=5d8b90d52f46fda7”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)
文件名:“Npgsql,区域性=中性,PublicKeyToken=5d8b90d52f46fda7”
警告:程序集绑定日志记录已关闭。
要启用程序集绑定失败日志记录,请将注册表值[HKLM\Software\Microsoft\Fusion!EnableLog](DWORD)设置为1。
注意:程序集绑定失败日志记录会带来一些性能损失。
要关闭此功能,请删除注册表值[HKLM\Software\Microsoft\Fusion!EnableLog]。
位于System.RuntimeTypeHandle.GetTypeByName(字符串名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、StackScrawMarkHandle stackMark、IntPtr pPrivHostBinder、布尔loadTypeFromPartialName、ObjectHandleOnStack类型)
在System.RuntimeTypeHandle.GetTypeByName(字符串名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、StackScrawlMark和stackMark、IntPtr pPrivHostBinder、布尔loadTypeFromPartialName)
在System.RuntimeType.GetType(字符串类型名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、堆栈爬网标记和堆栈标记)
at System.Type.GetType(字符串类型名)
位于System.Data.Common.DbProviderFactorys.GetFactory(DataRow providerRow)
位于System.Data.Common.DbProviderFactorys.GetFactory(字符串providerInvariantName)
位于System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(类型、对象键、Func`3 handleFailedLookup)
位于System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(类型,对象键)
在System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.c__DisplayClass1.b__0(元组'2k)
位于System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey,Func`2 valueFactory)
位于System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(类型,对象键)
在System.Data.Entity.Infrastructure.DependencyResolution.ResolverCain.c_uuDisplayClass3.b_uu0(IDBDendencyResolver)
在System.Linq.Enumerable.WhereSelectArrayInterator`2.MoveNext()中
在System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1源,Func`2谓词)
位于System.Data.Entity.Infrastructure.DependencyResolution.ResolverCain.GetService(类型,对象键)
位于System.Data.Entity.Infrastructure.DependencyResolver.RootDependencyResolver.GetService(类型,对象键)
在System.Data.Entity.Infrastructure.DependencyResolution.ResolverCain.c_uuDisplayClass3.b_uu0(IDBDendencyResolver)
在System.Linq.Enumerable.WhereSelectArrayInterator`2.MoveNext()中
在System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1源,Func`2谓词)
位于System.Data.Entity.Infrastructure.DependencyResolution.ResolverCain.GetService(类型,对象键)
位于System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(类型,对象键)
位于System.Data.Entity.Infrastructure.DependencySolveResolution.DbDependencySolveRextensions.GetService[T](IDBDendencySolver解析器,对象键)
位于System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(字符串providerInvariantName)
位于System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionString设置(ConnectionString设置appConfigConnection)
位于System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(字符串名称,AppConfig配置)
在System.Data.Entity.Internal.LazyInternalConnection.Initialize()中
在System.Data.Entity.Internal.LazyInternalConnection.get_Connection()中
在System.Data.Entity.Internal.LazyInternalContext.get_Connection()中
位于System.Data.Entity.Infrastructure.DbContextInfo..ctor(类型contextType、DbProviderInfo modelProviderInfo、AppConfig配置、DbConnectionInfo connectionInfo、Func`1解析器)
位于System.Data.Entity.Migrations.Dbmigator..ctor(DbMigrationsConfiguration配置、DbContext usersContext、DatabaseExistenceEstate ExistenceEstate、称为DbyCreateDatabase的布尔值)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置)
位于System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration MigrationConfiguration)
在System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()中
位于System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()处
无法加载文件或程序集“Npgsql,版本=4.1.1.0,区域性=中性,PublicKeyToken=5d8b90d52f46fda7”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)

我正在使用EntityFramework 6.2.0和EntityFramework.Npgsql 3.2.1.1。

Instala a versão 4.1.1 do Npgsql 安装程序包Npgsql-版本4.1.1下载

然后安装

更多信息请访问

Warning     Found conflicts between different versions of "Npgsql" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.