Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find or load Npgsql with Entity Framework

I am totally lost. In Visual Studio 2015, I created a WCF Library Service project and defined the service and service interface.

EntityFramework, EntityFramework.SqlServer, EntityFramework6.Npgsql, and Npgsql was installed with the NuGet console:

  • PM> Install-Package EntityFramework6.Npgsql -Version 3.0.5

Setting the library service as startup then starting debug (f5) correctly read the available procedures. However, upon testing any procedure in the WcfSvcHost, I get the following error:

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

What did I do wrong?

Here is the App.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- 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 -->
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="NovaMedicalService.MedicalService">
        <endpoint address="" binding="basicHttpBinding" contract="NovaMedicalService.IMedicalService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/NovaMedicalService/MedicalService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="chaosEntities" connectionString="metadata=res://*/ChaosModel.csdl|res://*/ChaosModel.ssdl|res://*/ChaosModel.msl;provider=Npgsql;provider connection string=&quot;Database=chaos;Host=localhost;Password=yuyuyu;Username=ooosos&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Can someone please help? I am totally lost.

TIA

like image 231
Alan Wayne Avatar asked Feb 16 '16 06:02

Alan Wayne


People also ask

Why can't I load Npgsql in Ado net?

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. · Issue #1439 · npgsql/npgsql · GitHub Have a question about this project?

What is the latest version of Npgsql and Entity Framework?

Latest version of Npgsql is 3.2.5, while latest version of EntityFramework5.Npgsql is only 3.1.1. Sorry, something went wrong. @ajelesin no, the Npgsql and EntityFramework5.Npgsql versions aren't synchronized.

How do I use the Npgsql EF Core Provider?

To use the Npgsql EF Core provider, add a dependency on Npgsql.EntityFrameworkCore.PostgreSQL. You can follow the instructions in the general EF Core Getting Started docs. Below is a .csproj file for a console application that uses the Npgsql EF Core provider:

Where do I report development issues for Entity Framework PostgreSQL?

Development happens in the Npgsql.EntityFrameworkCore.PostgreSQL repository, all issues should be reported there. To use the Npgsql EF Core provider, add a dependency on Npgsql.EntityFrameworkCore.PostgreSQL.


2 Answers

Problem solved. I neglected to add:

<system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
    </DbProviderFactories>
  </system.data>

(See Visual Studio Support (DDEX)

like image 84
Alan Wayne Avatar answered Nov 21 '22 09:11

Alan Wayne


uninstalling and reinstalling Npgsql.vsix resolved this problem.

like image 44
yikekas Avatar answered Nov 21 '22 09:11

yikekas