我正在尝试使用 PostgresSQL 和实体框架通过 WebAPI 配置 ASP.NET 4.5。我发现 Postgres 驱动程序 Npgsql 有两个单独的版本。版本 2.0.12.0 支持 EF 5.0.0.0。有一个单独的版本(根据错误标记为 2.0.13.91 的文档)支持 EF 6.0.0.0。我不在乎我使用哪个版本,只要我能让一个正常工作。我在尝试使用 EF 6.0.0.0 时遇到错误,我目前正在尝试让 5.0.0.0 工作(来自 6.0.0.0 的错误是一个单独的问题,如有必要,我将单独发布)。
现在的问题是,显然因为我已经安装了 EF 6.0.0.0,我无法完全降级到 EF 5.0.0.0。我已经恢复了所有可以找到的引用并且我只安装了 EF 5.0.0.0,但是当我部署 Web API 应用程序或尝试执行使用 Npgsql 驱动程序的代码时,我得到:
A first chance exception of type 'System.IO.FileLoadException' occurred in System.Data.Entity.dll
A first chance exception of type 'System.IO.FileLoadException' occurred in EntityFramework.dll
iisexpress.exe Error: 0 : Operation=ReflectedHttpActionDescriptor.ExecuteAsync, Exception=System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at Npgsql.NpgsqlFactory.GetService(Type serviceType)
at System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory)
我不知道 6.0.0.0 的规范来自哪里。我更新了web.config
. 我已经卸载并重新安装了 5.0.0.0。我什至卸载并重新安装了 MVC4 的 Visual Studio 更新包。Nuget 中列出的 EntityFramework 包是 5.0.0.0。包中所有引用的程序集都指定 EF 5.0.0.0。我重建了 Npgsql 并注册了重建的Npgsql.dll
和. 什么指向 6.0.0.0 以及如何恢复它?Mono.Security.dll
gacutil.exe
TL;博士
定位的程序集是 5.0.0.0,这是正确的。出于某种原因,它正在寻找 6.0.0.0,我不知道为什么。