using Microsoft.Data.Sqlclient in a CmdLet, gives PlatformNotSupportedException #15360
Unanswered
bzuidgeest
asked this question in
Q&A
Replies: 2 comments 2 replies
-
You'll most likely need to manually include and/or load the Microsoft.Data.SqlClient.dll before loading your cmdlet dll so that it's already present in the session before your cmdlet attempts to use those functions. For cases like this, I usually recommend packaging the module as a PSM1 which then loads the DLLs explicitly in the order they need to be loaded. |
Beta Was this translation helpful? Give feedback.
2 replies
-
You probably need to compile for a more specific version. For some packages, the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I trying to create a custom Cmdlet in c# for powershell 7. The CmdLet and one of the dependencies (a .net standard 2.0 lib) Both use Microsoft.Data.SqlClient. As soon as a try to use the CmdLet I get an error as soon as I try to open a sql connection:
customerDatabase = new SqlConnection(configuration.CustomerDatabase.ConnectionString);
customerDatabase.Open();
System.Exception
HResult=0x80131500
Message=Could not connect to customer Database
Inner Exception 1:
PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
From what I can gather this seems to have something to do with .net not choosing the correct dll for the platform and falling back to some kind of dummy dll. But I cannot find much on how to fix it (that I am able to understand). Lot's of stuff about when it happens to console or webapps, but little to nothing on powershell and custom cmdlets, I have not been able to adapt a solution.
cmdlet dll is loaded like C:\Program Files\PowerShell\7\pwsh.exe -NoExit -Command "& Import-Module .\VaultTech.Powershell.dll -Verbose; Test-SqlCmdlet"
Anyone here that can give me the proper pointers?
Beta Was this translation helpful? Give feedback.
All reactions