Closed pritiherkal closed 4 years ago
Please note that the script was run on an environment with only Az modules installed.
Sorry closed the bug by mistake. The issue is still open and need to be looked at. Thank you.
Best regards Priti
Thanks for reporting. We will look into it. @isra-fel please verify this one.
This issue looks like an old version of Microsoft.Azure.KeyVault
was loaded before Az.KeyVault
was imported. @pritiherkal could there be any chance that a module that depended on Microsoft.Azure.KeyVault
was imported in advance?
Additionally can you try installing PowerShell Core and let us know if the issue persists within PowerShell Core?
@isra-fel Thanks for your response.
My VM had AzureRM modules to start with and I uninstalled all the modules, restarted my VM and then installed the latest Az modules. I do not remember importing any modules in advance - Is there a way to find out if that happened? and please tell me which particular module it is?
Let me install Powershell Core and give it another try.
Best regards Priti
Hi @pritiherkal yes there is one way to verify:
[System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "*keyvault*"} | fl
to see if there's any keyvullt dll. It should output nothing on a fresh new powershell console.Import-Module az.keyvault
[System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "*keyvault*"} | fl
again. Now the keyvault dlls should be there.Hi @isra-fel, I ran the below commands on Powershell console and it behaved like you mentioned - it did not output anything at first, then the keyvault dll was there after running the import command.
PS C:\Users\PHerkal2> [System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "keyvault"} | fl
PS C:\Users\PHerkal2> Import-Module az.keyvault
PS C:\Users\PHerkal2> [System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "keyvault"} | fl
CodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Azure.KeyVault/v4.03.0.0.0 _31bf3856ad364e35/Microsoft.Azure.KeyVault.dll EntryPoint : EscapedCodeBase : file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.Azure.KeyVault/v4.03.0.0.0 _31bf3856ad364e35/Microsoft.Azure.KeyVault.dll FullName : Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 GlobalAssemblyCache : True HostContext : 0 ImageFileMachine : ImageRuntimeVersion : v4.0.30319 Location : C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Azure.KeyVault\v4.0_3.0.0.0__31bf385 6ad364e35\Microsoft.Azure.KeyVault.dll ManifestModule : Microsoft.Azure.KeyVault.dll MetadataToken : PortableExecutableKind : ReflectionOnly : False
CodeBase : file:///C:/Program Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.KeyVault.WebKey.dll EntryPoint : EscapedCodeBase : file:///C:/Program%20Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.Ke yVault.WebKey.dll FullName : Microsoft.Azure.KeyVault.WebKey, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 GlobalAssemblyCache : False HostContext : 0 ImageFileMachine : ImageRuntimeVersion : v4.0.30319 Location : C:\Program Files\WindowsPowerShell\Modules\az.keyvault\1.6.0\Microsoft.Azure.KeyVault.WebKey.dll ManifestModule : Microsoft.Azure.KeyVault.WebKey.dll MetadataToken : PortableExecutableKind : ReflectionOnly : False
CodeBase : file:///C:/Program Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.Management.KeyVault.dll EntryPoint : EscapedCodeBase : file:///C:/Program%20Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.Ma nagement.KeyVault.dll FullName : Microsoft.Azure.Management.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 GlobalAssemblyCache : False HostContext : 0 ImageFileMachine : ImageRuntimeVersion : v4.0.30319 Location : C:\Program Files\WindowsPowerShell\Modules\az.keyvault\1.6.0\Microsoft.Azure.Management.KeyVault.dll ManifestModule : Microsoft.Azure.Management.KeyVault.dll MetadataToken : PortableExecutableKind : ReflectionOnly : False
CodeBase : file:///C:/Program Files/WindowsPowerShell/Modules/Az.Accounts/1.7.5/Microsoft.Azure.Powe rShell.Clients.KeyVault.dll EntryPoint : EscapedCodeBase : file:///C:/Program%20Files/WindowsPowerShell/Modules/Az.Accounts/1.7.5/Microsoft.Azure.Po werShell.Clients.KeyVault.dll FullName : Microsoft.Azure.PowerShell.Clients.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 GlobalAssemblyCache : False HostContext : 0 ImageFileMachine : ImageRuntimeVersion : v4.0.30319 Location : C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.7.5\Microsoft.Azure.PowerShell.C lients.KeyVault.dll ManifestModule : Microsoft.Azure.PowerShell.Clients.KeyVault.dll MetadataToken : PortableExecutableKind : ReflectionOnly : False
CodeBase : file:///C:/Program Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.Powe rShell.Cmdlets.KeyVault.dll EntryPoint : EscapedCodeBase : file:///C:/Program%20Files/WindowsPowerShell/Modules/az.keyvault/1.6.0/Microsoft.Azure.Po werShell.Cmdlets.KeyVault.dll FullName : Microsoft.Azure.PowerShell.Cmdlets.KeyVault, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 GlobalAssemblyCache : False HostContext : 0 ImageFileMachine : ImageRuntimeVersion : v4.0.30319 Location : C:\Program Files\WindowsPowerShell\Modules\az.keyvault\1.6.0\Microsoft.Azure.PowerShell.C mdlets.KeyVault.dll ManifestModule : Microsoft.Azure.PowerShell.Cmdlets.KeyVault.dll MetadataToken : PortableExecutableKind : ReflectionOnly : False
It seems Microsoft.Azure.KeyVault is loaded from somewhere else.
You may try removing the folder C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Azure.KeyVault
.
Sure will try this out and get back @isra-fel
Hi @isra-fel
Removing the dll from GAC did work with Az scripts.
What I observed was that the Microsoft.Azure.KeyVault.dll
in GAC and in Az.KeyVault module folder are both v3.0.0.0 but file versions are different.
This dll in GAC is 3.0.3
whereas the one in Az.KeyVault module folder is 3.0.1
.
Though the dll in GAC is higher version, the method 'get_SerializationSettings' behaves differently between the two versions.
If v3.0.1 version of dll is GACed, the script runs fine. With the latest v3.0.5.0 dll in gac, the script runs fine too. I need the dll to be in GAC and will probably use either v3.0.1 or v3.0.5.0 version as a fix for this error, unless there is some why to getting this to work with v3.0.3 dll in gac.
One question on AzureRM modules: There are a few environments with AzureRM modules installed in them, and the error is similar but with a different dll -
Connect-AzureRmAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly
'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:1 char:1
+ Connect-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-AzureRmAccount], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
This Microsoft.Azure.Commands.ResourceManager.Common.dll
is not in GAC, any ideas on where else it is being loaded from before AzureRM.Profile
gets loaded?
PS C:\Users\pherkal2> [System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "Microsoft.Azure.Commands.ResourceManager.Common"} | fl
CodeBase : file:///C:/Program Files/WindowsPowerShell/Modules/AzureRM.Profile/4.6.0/Microsoft.Azure.Commands.ResourceManager.Common.dll
EntryPoint :
EscapedCodeBase : file:///C:/Program%20Files/WindowsPowerShell/Modules/AzureRM.Profile/4.6.0/Microsoft.Azure.Commands.ResourceManager.Common.dll
FullName : Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
GlobalAssemblyCache : False
HostContext : 0
ImageFileMachine :
ImageRuntimeVersion : v4.0.30319
Location : C:\Program Files\WindowsPowerShell\Modules\AzureRM.Profile\4.6.0\Microsoft.Azure.Commands.ResourceManager.Common.dll
ManifestModule : Microsoft.Azure.Commands.ResourceManager.Common.dll
MetadataToken :
PortableExecutableKind :
ReflectionOnly : False
Sorry but I have no idea... the AzureRM.Profile version you are using is too old. Some suggestions:
Get-Module AzureRM.profile -ListAvailable
Make sure you've installed only one versionThere is only one version of it installed for sure. Will give a try on updating the AzureRM modules or else will switch to Az.
Thank you @isra-fel for your help in finding the issue with the dll version of Az Keyvault.
You are welcome 😀
Description
I have a script which connects to Azure cloud using 'Connect-AzAccount' and then tries to get secrets stored in a KeyVault using 'Get-AzKeyVaultSecret'.
Error when running 'Get-AzKeyVaultSecret' command:
The original script was using AzureRM modules with 'Connect-AzureRmAccount' and 'Get-AzureKeyVaultSecret' commands which also threw a similar error:
Steps to reproduce
Using Az modules:
Environment data
Module versions
Debug output
Error output