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.
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:
Add the reference of the required version of the Npgsql .Net data provider in a new Visual Studio project.
Find and copy all the assemblies added by this provider in a folder.
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.
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
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With