Could not load type 'NpgsqlTypes.NpgsqlDbType'

Posts   
 
    
Posts: 8
Joined: 17-Jun-2005
# Posted on: 02-Nov-2023 07:46:38   

Hi,

Hopefully this is a stupid question and easy to answer. I've had no trouble with SQLServer and LLBLGen but this is my first Postgres project... I'm using the SelfServicing.General preset.

I'm getting the following exception when I try and use LLBLGen to access a PostgreSQL database using LLBLGen v5.10.1 on a .NET 6.0 console application running on Windows 10. The exception occurs on the line:

RuntimeConfiguration.ConfigureDQE<PostgreSqlDQEConfiguration>(c => c.AddDbProviderFactory(typeof(System.Data.SqlClient.SqlClientFactory)));

The exception is:

"System.TypeLoadException: 'Could not load type 'NpgsqlTypes.NpgsqlDbType' from assembly 'System.Data.SqlClient, Version=4.6.1.5, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'

The program.cs file contains:

using SD.LLBLGen.Pro.DQE.PostgreSql;
using SD.LLBLGen.Pro.ORMSupportClasses;
using Sra.NCS4.LLBLGen.CollectionClasses;
using Sra.NCS4.LLBLGen.DaoClasses;
using System.Data;

RuntimeConfiguration.ConfigureDQE<PostgreSqlDQEConfiguration>(c => c.AddDbProviderFactory(typeof(System.Data.SqlClient.SqlClientFactory)));
CommonDaoBase.ActualConnectionString = "Database=NCS4;Server=localhost;Port=5432;User Id=postgres;Password=mypassword";

SettingCollection sc = new SettingCollection();
sc.GetMulti(null);

Console.WriteLine($"There are {sc.Count} rows in the Setting table");*

My project file looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Npgsql" Version="7.0.6" />
    <PackageReference Include="SD.LLBLGen.Pro.DQE.PostgreSql" Version="5.10.2" />
    <PackageReference Include="SD.LLBLGen.Pro.ORMSupportClasses" Version="5.10.2" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\NCS4\Sra.NCS4.LLBLGen\Sra.NCS4.LLBLGen.csproj" />
  </ItemGroup>

</Project>

I have downloaded and installed Npgsql-4.0.13.msi (the only msi I could find), and I selected the GAC option.

Hopefully you can access my LLBLGen project file (Sra.NCS4.LLBLGen.llblgenproj) here:

https://sugarresearch-my.sharepoint.com/:u:/g/personal/plethbridge_sugarresearch_com_au/EXS5LmlqweFHqjTaHyLNolUB3SYqTM8JiAHfV3TrZ4UkFw?e=REZWOG

Maybe the problem is the version of Npgsql that I'm trying to use? Should I download the latest src from git, build and register in GAC manually?

Thanks in adavnce,

Phil

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 02-Nov-2023 09:36:23   

You don't need the MSI installation, you can add the Npgsql package from nuget (the latest) to your project that contains program.cs, and specify the Npgsql.NpgsqlFactory instead of the SqlClient factory in the call to AddDbProviderFactory() simple_smile (as you're using Npgsql, not SqlClient).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 8
Joined: 17-Jun-2005
# Posted on: 06-Nov-2023 05:42:51   

Otis wrote:

You don't need the MSI installation, you can add the Npgsql package from nuget (the latest) to your project that contains program.cs, and specify the Npgsql.NpgsqlFactory instead of the SqlClient factory in the call to AddDbProviderFactory() simple_smile (as you're using Npgsql, not SqlClient).

Thanks Otis