JTew JTew - 2 months ago 15
C# Question

How do I fix a DbProviderServices inheritance error for a MVC3 project on Mono 3.0.3, Entity Framework 6 Beta2 and Npgsql?

I have a MVC3 project targeting .net 4.5 running on Mono to the point where the only thing that is failing is the connection from Entity Framework to PostgreSQL.

I have an almost identical project working in VS 2012 with MVC4, EF6, Postgres.

I am getting the following error:


System.InvalidOperationException The 'Instance' member of the Entity
Framework provider type 'Npgsql.NpgsqlFactory, Npgsql' did not return
an object that inherits from
'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework
providers must extend from this class and the 'Instance' member must
return the Singleton instance of the provider.


Am I missing something in configuration or is this not going to work?

<!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468-->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->


And ...

<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql">
</provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>


Mono ASP.net version string ...

Version Information: 3.0.3 (master/39c48d5); ASP.NET Version: 4.0.30319.17020

Answer

I fixed this error.

Change

<entityFramework>
  <providers>
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql"></provider>
  </providers>
</entityFramework>

TO

  <entityFramework>
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql"></provider>
    </providers>
  </entityFramework>
Comments