title: Postgres & C#: Could not load type Npgsql.NpgsqlConnectionFactory
body: <p>I have been searching quite some time for some direction on this..unable to find the answer.</p>
  
  <p>Trying to connect to PostgreSQL by using .net Entity Framework (seems sensible, instead of writing my own framework around the normal sql connection method). </p>
  
  <p>On exeecuting the following lines of code, I get the error that follows below:</p>
  
  <pre><code>`using (var db = new dbTestContext())
  {
  var test = from a in db.dbTest select a;
  dataGridView1.DataSource = test.ToList();               
  }`
  </code></pre>
  
  <p>My Error:
  Outer Exception: </p>
  
  <blockquote>
    <p>{"Failed to set Database.DefaultConnectionFactory to an instance of the 'Npgsql.NpgsqlConnectionFactory, Npgsql' type as specified in the application configuration. See inner exception for details."}</p>
  </blockquote>
  
  <p>Inner Exception: </p>
  
  <blockquote>
    <p>{"Could not load type 'Npgsql.NpgsqlConnectionFactory' from assembly 'Npgsql'.":"Npgsql.NpgsqlConnectionFactory"}</p>
  </blockquote>
  
  <p>Setup:
  I have installed npgsql from NugetPackage Manager
  I have installed Entitiy Framework 6 for npgsql from Nuget Package Manager</p>
  
  <p>I have the following <code>App.Config</code> file (apologies, my first post, still trying to get the formatting correct). </p>
  
  <pre><code>`&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;!--&lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;--&gt;    
      &lt;defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" /&gt;
      &lt;providers&gt;
        &lt;!--&lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;--&gt;
        &lt;provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" /&gt;
      &lt;/providers&gt;    
    &lt;/entityFramework&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;      
        &lt;add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
    &lt;connectionStrings&gt;
      &lt;add name="dbTestConnectionString" connectionString="Server=localhost;Database=dbTest;User Id=postgres;Password=Dve835167!;" providerName="Npgsql" /&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;`
  </code></pre>
  
  <p>Any direction would be appreciated</p>