microsoft / SQLServerPSModule

This repo is the home of SQL Server PowerShell Module development.
MIT License
45 stars 1 forks source link

Method not found: 'Void Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider #65

Closed Tbablani72 closed 4 hours ago

Tbablani72 commented 7 months ago

I am trying to encrypt Azure SQL Database Columns Using Azure Automation Run Book. Code is written in power shell and is failing when trying to execute this command

$serverName = $serverName $connStr = "Server = " + $serverName + "; Database = " + $databaseName + ";Persist Security Info=False;Authentication =Active Directory Managed Identity;Encrypt=True;TrustServerCertificate=False;" $database = Get-SqlDatabase -ConnectionString $connStr Write-Output $database Set-SqlColumnEncryption -ColumnEncryptionSettings $EncryptionSettings -InputObject $database -LogFileDirectory . -KeyVaultAccessToken $keyVaultAccessToken

Error I get is as follows:

Failed Method not found: 'Void Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider..ctor(Azure.Core.TokenCredential)'. (Method not found: 'Void Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider..ctor(Azure.Core.TokenCredential)'.)

You can reference this existing issue on GitHub.
https://github.com/microsoft/SQLServerPSModule/issues/45
Matteo-T commented 7 months ago

Hi @Tbablani72 ,

The issue is most likely a duplicate of another one which is going to require a complete rewrite of the module, sadly. But maybe there is hope that we can patch it up somehow...

Would you happen to know what thos "Automation Run Book" are setup and run? I have no clue... (well, I think I did something a while back, but I completely forgot).

It would be nice to know how the environement this script runs in is setup... i.e. what modules are loaded before the sqlSERVER cmdletes are executed...

Best option for me would be to have a repro that does not involve the Automation Run Book...

if that is not possible, could you at least have the script temporarily updated to dump the output of:

  1. $PSVersionTable
  2. Get-Module (before and after running the script fragment that is failing)
  3. Get all the loaded assemblies before and after running the script fragment that is failing)
    [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location, GlobalAssemblyCache
  4. A description of the setup (I see there's an AVK, a DB, a managed identity, ...): how would I go about setting up an environment similar to that?
Matteo-T commented 7 months ago

This looks a lot like #45

@DBarmanMS - can you take a look at these issues and see if there's anything that we can suggest as workaround?

The ALC work is big and hardly coming any time soon... but perhaps we could play with our assembly resolution logic or maybe avoid this dependency in the AE cmdlet...

DBarmanMS commented 6 months ago

Hi @Tbablani72 , Could you please share a stand-alone script to reproduce this issue? I'm not able to reproduce this in my setup following the cmdlet article.

DBarmanMS commented 6 months ago

Easiest solution is to run the script in powershell 7. Please try it out and let me know if you face any issue.

JAK1047 commented 5 months ago

You can also install the older version of the module, zip it, then choose to add your own module in the Azure Automation Account instead of using the gallery and specifically use the 21.1.18256 version of SQLServer instead of 22 and above. Ran into the same issue with both RunBooks and normal scripts in the past when mixing in Az, PnP, or Graph modules and 21 never runs into the conflict for me.

shashank-nayak-na commented 4 months ago

We were facing the same error when trying to run PowerShell script from our Jenkins pipeline. Only thing that worked was to change the SQLServer version to 21.1.18256. Seems using the latest version throws the error.

vihanga-bandara commented 4 months ago

This worked for us in our release pipeline when we toggled 'Use powershell core' in the release definition under Advanced.

Matteo-T commented 4 days ago

A mitigation for this issue should become available in v22.3+, which I hope to release soon.

Matteo-T commented 4 hours ago

Please, give v22,3.0 a try. It has some mitigation in this area... Log a new issue if you still see something ugly...