CollaboratingPlatypus / PetaPoco

Official PetaPoco, A tiny ORM-ish thing for your POCO's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not load the PostgreSQLDatabaseProvider DbProviderFactory

yannicklal opened this issue · comments

I'm use to PetaPoco for years BUT, this time, I have to work with PostgreSQL. Despite of hours of tests I'm unable to connect the default database named postgres and get this error message: Could not load the PostgreSQLDatabaseProvider DbProviderFactory. Note that I can connect the database via psql wihtout difficulties.
I'm using PetaPoco.compiled 6.0.480. Here is my code (C# .NET Framework 4.8) :
string connStr = "Host=127.0.0.1;Username=postgres;Password=pwd;Database=postgres;Port=5432";
Database myMain = new Database(connStr, new PostgreSQLDatabaseProvider());

What am I missing ?

Does your project include the Npgsql NuGet package? PetaPoco assumes that you have the correct data provider available.

Yes it does runtime version v4.0.30319

That's pretty old -- what's the NuGet package version?

Nuget package version 6.0.5.0

Oh, okay, that's current, not sure why the runtime version is different.

I'm not sure what to say -- the basic code you have above works fine for me (using my own Postgres connection string, of course). It seems like PP is just not finding the Npgsql libraries at runtime.

Thanks for your reply, indeed I'm using PetaPoco in a library. At runtime Petapoco.dll is copied in the bin directory but Npgsql libraries don't. I'm using VS22 how achieve that copy at runtime?

Using it in a library shouldn't matter. If your package references are all correct, then things should get copied correctly.

Yes I'm agree but how can I check if my package references are all correct? Could you give me an example?

If you can post the skeleton of your solution here, or point me to your repo, I can take a look at what you have.

I sent you an invitation thanks for your precious help!

The short answer is that using a project reference like this is not the same as consuming a NuGet package. If Kiwy consumed Kiwy.Core as a NuGet package, then all the dependencies would come along for the ride. But adding a project reference from Kiwy to Kiwy.Core is literally just like adding a reference to Kiwy.Core.dll (except that you can debug into the Kiwy.Core methods) — packages that Kiwy.Core depends on do not get copied over to the Kiwy bin folder.

The solution here is that you need to explicitly add to Kiwy all the NuGet packages that Kiwy.Core needs.

All right! thank you very much