Reputation: 1526
I am attempting to configure ASP.NET 4.5 with WebAPI using PostgresSQL and Entity framework. I have discovered that there are two separate builds of the Postgres driver Npgsql. Version 2.0.12.0 supports EF 5.0.0.0. There is a separate build (which is according to the documentation incorrectly labeled as 2.0.13.91) supporting EF 6.0.0.0. I don't care which versions I use as long as I can get one to work properly. I get an error attempting to use EF 6.0.0.0 and I am currently trying to get 5.0.0.0 to work (the error from 6.0.0.0 is a separate issue and I will post about that separately if necessary).
The problem now is that apparently because I already installed EF 6.0.0.0 at one point, I cannot fully downgrade to EF 5.0.0.0. I have reverted all references that I can find and I have only EF 5.0.0.0 installed, but when I deploy the web API application or attempt to execute code that uses the Npgsql driver, I get:
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)
I don't know where the specification of 6.0.0.0 is coming from. I updated all the version specifications in web.config
. I have uninstalled and reinstalled 5.0.0.0. I even uninstalled and reinstalled the Visual Studio update package for MVC4. The EntityFramework package listed in Nuget is 5.0.0.0. All of the referenced assemblies in the package specify EF 5.0.0.0. I rebuilt Npgsql and registered the rebuilt Npgsql.dll
and Mono.Security.dll
with gacutil.exe
. What is pointing to 6.0.0.0 and how do I revert it?
TL;DR
The located assembly is 5.0.0.0, which is correct. For some reason it's looking for 6.0.0.0 and I can't figure out why.
Upvotes: 4
Views: 4918
Reputation: 774
I'd been having the same problem, and fortunately, had a test version deployed on another server prior to my accidentally upgrading (and subsequent downgrading) to EF6. So, I pulled the config file from that server, and was able to just overwrite the config that was causing the problems. Once I got it working, I diff-ed the version from the server with the one I've got locally, and noticed that there's a providers section on my machine that wasn't on the server (see below). Once that had been removed, it worked for me. Unclear if it's just a case of a downgrade not performing a complete clean up.
<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>
I'm in the middle of a deployment, so apologies for this answer only being anecdotal. Hope this works for you!
Upvotes: 1