Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npgsql v5.0.0 GAC installation

Tags:

.net

gac

npgsql

As given in the Npgsql version 5.0 release notes(Breaking changes) here, MSI GAC installer have been discontinued. The statement from the release notes is given below:

Npgsql no longer targets .NET Framework 4.6.1. Since .NET Standard 2.0 is targeted, it is still possible to use Npgsql from .NET Framework applications; however, we no longer run regression tests on .NET Framework and will only fix bugs on a best-effort basis. In addition, the Visual Studio extension (VSIX) and the MSI GAC installer have been discontinued. #3269.

The problem which I am facing owing to this change is that my clients were using the MSI installer to install the Npgsql in GAC and my application loads its factory dynamically using System.Data.Common.DbProviderFactories of .Net framework. This gives me the flexibility to let the client choose their required provider version depending upon their database version.

Switching to the nuget package installation will add an overhead to update Npgsql packages within my application. Therefore, I want to avoid this route. Is there any way to still install the latest Npgsql 5.0 version in GAC as done by the MSI installer?

If yes, please let me know the steps to do it.

like image 801
prem Avatar asked Mar 16 '26 05:03

prem


1 Answers

Finally, I got it working by registering all the assemblies in GAC using gacutil.exe.

I am using .Net framework 4.6.1 in my application and I have performed the following steps to install the Npgsql version 5.0.0.0 in GAC:

  1. Add the reference of the required version of the Npgsql .Net data provider in a new Visual Studio project.

  2. Find and copy all the assemblies added by this provider in a folder.

  3. Now we need to use gacutil.exe to register these assemblies in GAC. It can be used with Visual Studio command prompt or it comes with Windows SDK.

  4. Use the command with Admin privileges and run the below command for each assembly. gacutil.exe /i "AssemblyPath/assemblyName.dll"

For the version 5.0.0.0, the complete list of commands are given below:

   gacutil.exe /i Npgsql.dll
   gacutil.exe /i Microsoft.Bcl.AsyncInterfaces.dll
   gacutil.exe /i System.Buffers.dll
   gacutil.exe /i System.Memory.dll
   gacutil.exe /i System.Numerics.Vectors.dll
   gacutil.exe /i System.Runtime.CompilerServices.Unsafe.dll
   gacutil.exe /i System.Text.Encodings.Web.dll
   gacutil.exe /i System.Text.Json.dll  
   gacutil.exe /i System.Threading.Channels.dll
   gacutil.exe /i System.Threading.Tasks.Extensions.dll
   gacutil.exe /i System.ValueTuple.dll
  1. Now add the below entry in machine.config file at two locations

Location 1: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

Location 2: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

Config Entry:

 <system.data>
        <DbProviderFactories><add name="Npgsql Data Provider" invariant="Npgsql" description=".NET Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5D8B90D52F46FDA7"/></DbProviderFactories>
 </system.data>
  1. In the current version 5.0.0.0, Npgsql is trying to find out the lower versions of dependent assemblies. I think this is a bug and they might fix this issue in later versions but for now we need to make some entries of the dependent assemblies in our application App.confg file to use these versions instead.

YourApplication.exe.config can be found in the installation directory and you need to add the below lines under the <assemblyBinding> section:

<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.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.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.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>

Now I can easily get the DbProviderFactory instance in my application without any issue.

like image 64
prem Avatar answered Mar 18 '26 22:03

prem