Search code examples
c#.netnpgsqldbproviderfactories

How to remove a provider from DbProviderFactories?


(Configuration: VS 2015 community, Windows 10 64bit, .Net 4.6.1)

At one point I installed

Npgsql Data Provider .Net Data Provider for PostgreSQL Npgsql Npgsql.NpgsqlFactory, Npgsql, Version=3.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7

to be used by

DbProviderFactories.GetFactoryClasses().

I am now trying to remove it.

  • I have removed all connection strings and the xml element from the project's App.config.

  • From both

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\CONFIG\machine.config

and

%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config

I removed the provider declaration in DbProviderFactories

add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql"

  • Using gacutil /u npgsql, I removed all npgsql references from the GAC:

gacutil /l Npgsql Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0 Copyright (c) Microsoft Corporation. All rights reserved.

The Global Assembly Cache contains the following assemblies:

Number of items = 0

So after removing Npgsql provider from the machine.config's, the App.config, and the GAC, DbProviderFactories.GetFactoryClasses() still reports:

Npgsql Data Provider .Net Data Provider for PostgreSQL Npgsql Npgsql.NpgsqlFactory, Npgsql, Version=3.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7

What else do I need to do to convince DbProviderFactories that Npgsql is not a provider??

Thanks much for any help on this.

Edit#1: I never could "remove" the Npgsql provider, but rebuiling with a target framework of NET 4.5.2 (instead ofNET 4.6.1) did solve much of the other problems.

Edit#2: I need to come back to this, but it is interesting that Visual Studio 2015 Community has its own configuration for DbProvderFactories at

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe.config


Solution

  • In the generic sense, I bet removing it from devenv.exe.config will finish its removal. However, in this specific case, it turns out that the Npgsql Development Team already installs an uninstaller app at:

    C:\Program Files (x86)\The Npgsql Development Team\Npgsql

    labeled, uninstall.exe.

    (I could find no information on this).

    Late Update In playing with PetaPoco, the Npgsql provider could not be found dispite it being added to the GAC and the machine.config files. Looking into devenv.exe.config, this was found:

    <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=3.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
    

    which was referring to the wrong Npgsql version. Removing this from the devenv.exe.config file and restarting Visual Studio allowed PetaPoco to correctly find the Npgsql provider from the machine.confg and GAC.