我正在尝试使用Postgressql和Entity框架使用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,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.dll和Mono.Security.dll.什么指向6.0.0.0,我该如何还原它?
TL; DR
定位的程序集是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>
我正处于部署的中间,所以对这个答案道歉只是轶事.希望这对你有用!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。