Click here to Skip to main content
14,691,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

<?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" />
      </configSections>
      <entityFramework>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
          <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
        </providers>
      </entityFramework>
      <system.data>
        <DbProviderFactories>
          <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
        </DbProviderFactories>
      </system.data>
      <connectionStrings>
        <add name="KMSystemContext" connectionString="Server=****;Database=KMSystem;User Id=postgres;Password=***;" providerName="Npgsql" />
      </connectionStrings>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>


Installed packages are :
Npgsql 4.1.5
EntityFramework 6.0.0.0

What I have tried:

I am using Code-First project and my database is PostgreSql. When I migrated my project to PostgreSql by using Npgsql v.2.2.7 everything worked fine. I need to use the new version of Npsql. To achieve my goal I upgraded Npsql to the latest version (4.1.5). Now when I use add-migration I get the following error :
Posted
Updated 8-Oct-20 23:29pm
Comments
Maciej Los 7-Oct-20 2:43am
   
You have to use Entity Framework 6 for Npgsql. See: Entity Framework 6 | Npgsql Documentation[^]

Move to Entity Framework Core. The level of support (docs) compared to EF 6.0 should make EF 6.0 a non-starter (for pgsql).

Getting Started | Npgsql Documentation[^]

Entity Framework 6 | Npgsql Documentation[^]
   
After a while of searching we installed EntityFramework6.Npgsql 6.4.1 package in all solution's projects (There are some class liberaries and WinApps projects in the solution). With the update of this package, Npgsql update to the new version (4.1.3) too. So the app.config change to :
<entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
    </providers>
    <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, EntityFramework6.Npgsql" />
</entityFramework>

It needs to be changed app.config as below. Just in the project that DataContext has located (DataLayer)
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />

Replace with :
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />

at the end, we have to set DataLayer (With DataContext) as StartUp Project. (Set as StartUp Project) and then we can migrate code first project with PostgreSql database by using add-migration and update-database commands in PackageManagerConsole.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900