Could not find or load Npgsql using Entity Framework

I am completely lost. In Visual Studio 2015, I created a WCF library service project and defined a service and service interface.

EntityFramework, EntityFramework.SqlServer, EntityFramework6.Npgsql and Npgsql were installed from the NuGet console:

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

Configure the library service as startup, and then start debugging (f5) correctly read the available procedures. However, when checking any procedure in WcfSvcHost, I get the following error:

The ADO.NET provider with the invariant name "Npgsql" is either not registered in the device or application configuration file or cannot be loaded. See Internal Exception for more details.

What have I done 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 
  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>

- ? .

+4
1

. :

<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>

(. Visual Studio (DDEX)

+6

Source: https://habr.com/ru/post/1628927/


All Articles