c# - 将 EntityFramework 6.0.0.0 还原为 5.0.0.0

标签 c# entity-framework asp.net-mvc-4 asp.net-web-api npgsql

我正在尝试使用 PostgresSQL 和 Entity Framework 通过 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,并用 gacutil.exe 注册了重建的 Npgsql.dllMono.Security.dll。什么指向 6.0.0.0,我该如何还原它?

长话短说

定位到的程序集是5.0.0.0,是正确的。出于某种原因,它正在寻找 6.0.0.0,但我不明白为什么。

最佳答案

我一直遇到同样的问题,幸运的是,在我不小心升级(以及随后降级)到 EF6 之前,在另一台服务器上部署了一个测试版本。因此,我从该服务器中提取了配置文件,并且能够覆盖导致问题的配置。一旦我开始工作,我将服务器的版本与我在本地获得的版本进行了区分,并注意到我的机器上有一个供应商部分不在服务器上(见下文)。删除后,它对我有用。不清楚这是否只是降级未执行完全清理的情况。

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

  <!-- This providers section appeared after the accidental upgrade to EF6 once it was removed, application no longer expected EF6 dlls -->
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

我正在部署中,所以很抱歉这个答案只是轶事。希望这对你有用!

关于c# - 将 EntityFramework 6.0.0.0 还原为 5.0.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438269/

相关文章:

c# - 如何在运行时更改 SystemAccentColor (UWP)?

c# - 对带参数的抽象工厂进行单元测试

c# - 如何在 EF 中批量更新

sql-server - 使用相当于 sql IN 运算符的 linq

c# - MVC 4 默认参数值

c# - 如何在asp.net mvc中执行每月的特定进程?

c# - 如何绘制一个圆形按钮并在其上制作标签

c# - 当需要保留某个执行顺序时运行一堆异步任务

c# - 将 List<string> 转换为 EntityFramework 列/字段列表

c# - 在 asp.net mvc5 中使用自定义登录进行表单例份验证