Consuming Npgsql inside PowerShell 5.1
See original GitHub issueThe issue
I am trying to consume the npgsql package with PowerShell 5.1. I tried out three versions:
- 5.0.3
- 4.1.8
- 4.0.11 Only 4.0.11 seems to work.
Steps to reproduce
4.0.11: Add-Type -Path “npgsql.dll” This works.
4.1.8: Add-Type -Path “npgsql.dll” results in add-type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more informati on.
try {
Add-Type -Path "npgsql.dll"
}
catch {
$err = $_
}
$err.Exception.LoaderExceptions
yields:
Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc
7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
5.0.3: Also yields
Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc
7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
I fiddled with additional Add-Type and also provided the -ReferencedAssemblies parameter but to no avail.
Further technical details
Operating system: Windows 10
Other details about my project setup: PowerShell 5.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Using npgsql via powershell 5.1 with .net 4.x
Using npgsql via powershell 5.1 with .net 4.x. ... After loading npgsql.dll the others will be loaded in lazy mode automatically. The connection...
Read more >How to import the npgsql module? - postgresql
Download Npgsql-3.0.5.msi from the npgsql website and run the installer · Search for a DLL named 'Npgsql.ll' · Copy this dll to your...
Read more >Powershell and Postgres – improving INSERT performance
I have a postgres database which I populate via a powershell script. I'm having trouble with the time it takes to for the...
Read more >ODBC Calling Fill - Unexptected closed connection after 2 hours
I have a query that is executed through an ODBC connection in a Powershell 5.1 script. I use the Fill() method to retreive...
Read more >Provisioning Azure SQL database using Azure PowerShell
This article will show how to create an Azure SQL database using Azure PowerShell.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just out of curiosity I tried how Npgsql would work from a current PowerShell and got the following example to run:
Hi @KrisztianKaszas, my example above also works on PowerShell 5.1.x but you have to be aware of the fact that the “classic” PowerShell versions rely on .NET Framewok (4.5 to be precise). This is why Npgsql 4.0.x is the latest version you can use. Also since Npgsql for .NET framework needs a few NuGet packages to work you have to make sure that they are also available and resolved in the appropriate way. This makes my example a bit longer but it should still work.
Full disclosure: After successfully executing the above code I sometimes run into a StackOverflowException terminating my PowerShell process when I keep executing commands afterwards.
I’m not sure if/how it is related as it happens completely independent of my script execution but it is at least a weird coincidence.Edit: It turns out that it was the customResolveEventHandler
that caused the crashes (executing the script in pwsh which didn’t crash gave me the hint). I’ve updated the script to unregister the handler after the assemblies have been resolved.