4

我正在尝试使用 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.dllgacutil.exe

TL;博士

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

4

1 回答 1

1

我遇到了同样的问题,幸运的是,在我意外升级(以及随后的降级)到 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>

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

于 2013-11-07T12:58:37.043 回答