Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.22k stars 3.83k forks source link

Get-AzKeyVaultSecret : Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation #11869

Closed pritiherkal closed 4 years ago

pritiherkal commented 4 years ago

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:

_Get-AzKeyVaultSecret : Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 
'Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:13 char:12
+ $secret = (Get-AzKeyVaultSecret -vaultName $KVName -name $sharedAcces ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzKeyVaultSecret], TypeLoadException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret_

The original script was using AzureRM modules with 'Connect-AzureRmAccount' and 'Get-AzureKeyVaultSecret' commands which also threw a similar error:

_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:7 char:1
+ Connect-AzureRmAccount -ServicePrincipal -Credential $pscredential -T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-AzureRmAccount], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand 

Get-AzureKeyVaultSecret : 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:12 char:12
+ $secret = (Get-AzureKeyVaultSecret -vaultName $KVName -name $sharedAc ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AzureKeyVaultSecret], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret_ 

Steps to reproduce

Using Az modules:

Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId
Get-AzKeyVaultSecret -vaultName $KVName -name $sharedAccessKeyName

Environment data

Name                           Value                                                                              
----                           -----                                                                              
PSVersion                      5.1.14393.3471                                                                     
PSEdition                      Desktop                                                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                            
BuildVersion                   10.0.14393.3471                                                                    
CLRVersion                     4.0.30319.42000                                                                    
WSManStackVersion              3.0                                                                                
PSRemotingProtocolVersion      2.3                                                                                
SerializationVersion           1.1.0.1

Module versions


ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Script     1.7.5      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave,...
Script     1.1.1      Az.Advisor                          {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecomme...
Script     1.0.3      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCred...
Script     1.1.2      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisS...
Script     1.4.1      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagement...
Script     1.0.3      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights...
Script     1.3.6      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomati...
Script     2.0.2      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBat...
Script     1.0.2      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnr...
Script     1.4.3      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnP...
Script     1.3.0      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServi...
Script     3.7.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New...
Script     1.0.3      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-A...
Script     1.1.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Up...
Script     1.1.0      Az.DataBoxEdge                      {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdgeDevice, Invok...
Script     1.7.0      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzD...
Script     1.0.2      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAna...
Script     1.2.8      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataL...
Script     1.1.0      Az.DeploymentManager                {Get-AzDeploymentManagerArtifactSource, New-AzDeploym...
Script     1.0.2      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdown...
Script     1.1.2      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-Az...
Script     1.2.3      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEv...
Script     1.4.3      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Se...
Script     1.4.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, R...
Script     3.1.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinitio...
Script     1.0.1      Az.HealthcareApis                   {New-AzHealthcareApisService, Remove-AzHealthcareApis...
Script     2.4.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, ...
Script     1.6.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertific...
Script     1.3.2      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegration...
Script     1.1.3      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAs...
Script     1.0.0      Az.Maintenance                      {Get-AzApplyUpdate, Get-AzConfigurationAssignment, Ge...
Script     1.0.2      Az.ManagedServices                  {Get-AzManagedServicesAssignment, New-AzManagedServic...
Script     1.0.2      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}        
Script     1.1.1      Az.Media                            {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey...
Script     1.7.0      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogPr...
Script     2.5.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, G...
Script     1.1.1      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthoriz...
Script     1.3.4      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource,...
Script     1.3.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicySt...
Script     1.1.1      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWo...
Script     1.0.2      Az.PrivateDns                       {Get-AzPrivateDnsZone, Remove-AzPrivateDnsZone, Set-A...
Script     2.8.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecovery...
Script     1.2.1      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheSc...
Script     1.0.3      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRe...
Script     1.13.0     Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Ge...
Script     1.4.1      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace...
Script     2.0.2      Az.ServiceFabric                    {Add-AzServiceFabricClientCertificate, Add-AzServiceF...
Script     1.1.1      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-...
Script     2.6.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSq...
Script     1.1.0      Az.SqlVirtualMachine                {New-AzSqlVM, Get-AzSqlVM, Update-AzSqlVM, Remove-AzS...
Script     1.14.0     Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-A...
Script     1.2.3      Az.StorageSync                      {Invoke-AzStorageSyncCompatibilityCheck, New-AzStorag...
Script     1.0.1      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalytics...
Script     1.0.0      Az.Support                          {Get-AzSupportService, Get-AzSupportProblemClassifica...
Script     1.0.3      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-A...
Script     1.8.0      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAp...
Script     0.5.4      Azure.AnalysisServices              {Add-AzureAnalysisServicesAccount, Restart-AzureAnaly...
Script     4.6.1      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken...
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}   
Script     1.4.7      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-...
Script     3.4.0      Pester                              {Describe, Context, It, Should...}                      
Script     2.2.4.1    PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-Ro...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Mod...
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, ...

    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-AppBa...
Manifest   2.0.0.0    AppLocker                           {Get-AppLockerFileInformation, Get-AppLockerPolicy, N...
Manifest   1.0.0.0    AppvClient                          {Add-AppvClientConnectionGroup, Add-AppvClientPackage...
Manifest   2.0.0.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageMan...
Script     1.0.0.0    AssignedAccess                      {Clear-AssignedAccess, Get-AssignedAccess, Set-Assign...
Manifest   1.0        BestPractices                       {Get-BpaModel, Get-BpaResult, Invoke-BpaModel, Set-Bp...
Manifest   1.0.0.0    BitLocker                           {Unlock-BitLocker, Suspend-BitLocker, Resume-BitLocke...
Manifest   2.0.0.0    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfe...
Manifest   1.0.0.0    BranchCache                         {Add-BCDataCacheExtension, Clear-BCCache, Disable-BC,...
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInst...
Manifest   1.0        ConfigCI                            {Get-SystemDriver, New-CIPolicyRule, New-CIPolicy, Ge...
Manifest   1.0        Defender                            {Get-MpPreference, Set-MpPreference, Add-MpPreference...
Binary     2.0.0.0    DFSR                                {New-DfsReplicationGroup, Get-DfsReplicationGroup, Se...
Manifest   1.0.0.0    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection, Enable-DAManual...
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-WindowsDriver, Add-W...
Manifest   1.0.0.0    DnsClient                           {Resolve-DnsName, Clear-DnsClientCache, Get-DnsClient...
Manifest   1.0.0.0    EventTracingManagement              {New-EtwTraceSession, Get-EtwTraceSession, Set-EtwTra...
Script     1.0.0.0    IISAdministration                   {Get-IISAppPool, Start-IISCommitDelay, Stop-IISCommit...
Manifest   2.0.0.0    International                       {Get-WinDefaultInputMethodOverride, Set-WinDefaultInp...
Manifest   1.0.0.0    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTargetPortal, Remove...
Manifest   2.0.0.0    IscsiTarget                         {Add-ClusteriSCSITargetServerRole, Add-IscsiVirtualDi...
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}     
Manifest   1.0.0.0    Kds                                 {Add-KdsRootKey, Get-KdsRootKey, Test-KdsRootKey, Set...
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                      
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Co...
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                     
Manifest   1.0.0.0    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-Loca...
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join...
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy                               
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wid...
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSMan...
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set-MMAgent, Get-MM...
Manifest   1.0.0.0    MsDtc                               {New-DtcDiagnosticTransaction, Complete-DtcDiagnostic...
Manifest   2.0.0.0    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapterBinding, Disab...
Manifest   1.0.0.0    NetConnection                       {Get-NetConnectionProfile, Set-NetConnectionProfile}    
Manifest   1.0.0.0    NetEventPacketCapture               {New-NetEventSession, Remove-NetEventSession, Get-Net...
Manifest   2.0.0.0    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic, Get-NetLb...
Manifest   1.0.0.0    NetNat                              {Get-NetNat, Get-NetNatExternalAddress, Get-NetNatSta...
Manifest   2.0.0.0    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, Remove-NetQosPol...
Manifest   2.0.0.0    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuthProposal, New-Ne...
Manifest   1.0.0.0    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchTeam, Get-NetSwit...
Manifest   1.0.0.0    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface, Get-NetIPv4Pro...
Manifest   1.0.0.0    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPolicyConfiguration,...
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwi...
Manifest   1.0.0.0    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-NetDnsTransitionC...
Manifest   1.0        NFS                                 {Get-NfsMappedIdentity, Get-NfsNetgroup, Install-NfsM...
Manifest   1.0.0.0    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, Stop-PcsvDevice, R...
Manifest   1.0.0.0    PKI                                 {Add-CertificateEnrollmentPolicyServer, Export-Certif...
Manifest   1.0.0.0    PlatformIdentifier                  Get-PlatformIdentifier                                  
Manifest   1.0.0.0    PnpDevice                           {Get-PnpDevice, Get-PnpDeviceProperty, Enable-PnpDevi...
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-PrinterPort, Get...
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfigura...
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disab...
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, G...
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession...
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow                                       
Manifest   2.0.0.0    RemoteDesktop                       {Get-RDCertificate, Set-RDCertificate, New-RDCertific...
Manifest   1.0.0.0    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask, Register-Sched...
Manifest   2.0.0.0    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBootUEFI, Get-Secu...
Manifest   1.0.0.0    SecurityCmdlets                     {Backup-SecurityPolicy, Restore-SecurityPolicy, Backu...
Script     1.0.0.0    ServerCore                          {Get-DisplayResolution, Set-DisplayResolution}          
Script     2.0.0.0    ServerManager                       {Get-WindowsFeature, Install-WindowsFeature, Uninstal...
Cim        1.0.0.0    ServerManagerTasks                  {Get-SMCounterSample, Get-SMPerformanceCollector, Sta...
Manifest   2.0.0.0    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-SmbShare, Block-S...
Manifest   2.0.0.0    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnessClient, gsmbw, ...
Manifest   2.0.0.0    SoftwareInventoryLogging            {Get-SilComputer, Get-SilComputerIdentity, Get-SilSof...
Manifest   1.0.0.0    StartLayout                         {Export-StartLayout, Import-StartLayout, Get-StartApps} 
Manifest   2.0.0.0    Storage                             {Add-InitiatorIdToMaskingSet, Add-PartitionAccessPath...
Manifest   2.0.0.0    TLS                                 {New-TlsSessionTicketKey, Enable-TlsSessionTicketKey,...
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}   
Manifest   2.0.0.0    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unblock-Tpm...}    
Binary     2.1.639.0  UEV                                 {Clear-UevConfiguration, Clear-UevAppxPackage, Restor...
Manifest   1.0.0.0    UserAccessLogging                   {Enable-Ual, Disable-Ual, Get-Ual, Get-UalDns...}       
Manifest   2.0.0.0    VpnClient                           {Add-VpnConnection, Set-VpnConnection, Remove-VpnConn...
Manifest   1.0.0.0    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDsn, Add-Odb...
Manifest   1.0.0.0    WebAdministration                   {Start-WebCommitDelay, Stop-WebCommitDelay, Get-WebCo...
Manifest   2.0.0.0    Whea                                {Get-WheaMemoryPolicy, Set-WheaMemoryPolicy}            
Manifest   1.0.0.0    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Unregister-WindowsDevel...
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disable-WindowsErrorRe...
Manifest   1.0.0.0    WindowsSearch                       {Get-WindowsSearchSetting, Set-WindowsSearchSetting}    
Manifest   1.0.0.0    WindowsUpdate                       Get-WindowsUpdateLog                                    

    Directory: C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Manifest   1.0        SQLPS                               {Backup-SqlDatabase, Save-SqlMigrationReport, Add-Sql...

    Directory: C:\Program Files\Service Bus\1.1

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Binary     1.0        ServiceBus                          {Add-SBHost, Disable-SBHostCEIP, Enable-SBHostCEIP, G...

    Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\7.3.702.0

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Binary     1.0        HybridRegistration                  {Add-HybridRunbookWorker, Remove-HybridRunbookWorker,...

    Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\7.3.702.0\HybridAgent\Modules

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Binary     1.0        Orchestrator.AssetManagement.Cmd... {Get-AutomationCertificate, Get-AutomationConnection,...

    Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell

ModuleType Version    Name                                ExportedCommands                                        
---------- -------    ----                                ----------------                                        
Binary     1.0.0.0    Microsoft.MonitoringAgent.PowerS... {Checkpoint-WebApplicationMonitoring, Get-WebApplicat...

Debug output

DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - True; Duration - 00:00:00.4922921;
DEBUG: Finish sending metric.
DEBUG: 09:05:56 - ConnectAzureRmAccountCommand end processing.
DEBUG: 09:05:56 - GetAzureKeyVaultSecret begin processing with ParameterSet 'ByVaultName'.
DEBUG: 09:05:56 - using account id 'SPNID'...
Get-AzKeyVaultSecret : Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, 
Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:13 char:11
+ $secret = Get-AzKeyVaultSecret -vaultName $KVName -name $sharedAccess ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzKeyVaultSecret], TypeLoadException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret

DEBUG: AzureQoSEvent: CommandName - Get-AzKeyVaultSecret; IsSuccess - False; Duration - 00:00:00.0149250;; Exception - System.TypeLoadException: Method 'get_Seria
lizationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf
3856ad364e35' does not have an implementation.
   at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultDataServiceClient..ctor(IAuthenticationFactory authFactory, IAzureContext context)
   at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultCmdletBase.get_DataServiceClient()
   at Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 09:05:56 - GetAzureKeyVaultSecret end processing.

Error output

DEBUG: 09:09:25 - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 09:09:25 - using account id 'SPNID'...
WARNING: Breaking changes in the cmdlet 'Resolve-AzError' :
WARNING:  - The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError` instead.

WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure Po
werShell.

   HistoryId: 5

Message        : Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, 
                 Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
StackTrace     :    at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultDataServiceClient..ctor(IAuthenticationFactory authFactory, IAzureContext context)
                    at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultCmdletBase.get_DataServiceClient()
                    at Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.TypeLoadException
InvocationInfo : {Get-AzKeyVaultSecret}
Line           : $secret = Get-AzKeyVaultSecret -vaultName $KVName -name $sharedAccessKeyName

Position       : At line:13 char:11
                 + $secret = Get-AzKeyVaultSecret -vaultName $KVName -name $sharedAccess ...
                 +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 5

   HistoryId: 4

Message        : Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, 
                 Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
StackTrace     :    at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultDataServiceClient..ctor(IAuthenticationFactory authFactory, IAzureContext context)
                    at Microsoft.Azure.Commands.KeyVault.Models.KeyVaultCmdletBase.get_DataServiceClient()
                    at Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.TypeLoadException
InvocationInfo : {Get-AzKeyVaultSecret}
Line           :             $secret = Get-AzKeyVaultSecret -VaultName $KVName -Name $sharedAccessKeyName

Position       : At line:136 char:23
                 + ...   $secret = Get-AzKeyVaultSecret -VaultName $KVName -Name $sharedAcce ...
                 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 4

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

DEBUG: AzureQoSEvent: CommandName - Resolve-AzError; IsSuccess - True; Duration - 00:00:00.0981899;
DEBUG: Finish sending metric.
DEBUG: 09:09:26 - ResolveError end processing.
pritiherkal commented 4 years ago

Please note that the script was run on an environment with only Az modules installed.

pritiherkal commented 4 years ago

11865

pritiherkal commented 4 years ago

Sorry closed the bug by mistake. The issue is still open and need to be looked at. Thank you.

Best regards Priti

dingmeng-xue commented 4 years ago

Thanks for reporting. We will look into it. @isra-fel please verify this one.

isra-fel commented 4 years ago

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?

pritiherkal commented 4 years ago

@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

isra-fel commented 4 years ago

Hi @pritiherkal yes there is one way to verify:

  1. Call [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.
  2. Import-Module az.keyvault
  3. Call [System.AppDomain]::CurrentDomain.GetAssemblies() | ? {$_.FullName -ilike "*keyvault*"} | fl again. Now the keyvault dlls should be there.
pritiherkal commented 4 years ago

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

isra-fel commented 4 years ago

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.

pritiherkal commented 4 years ago

Sure will try this out and get back @isra-fel

pritiherkal commented 4 years ago

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
isra-fel commented 4 years ago

Sorry but I have no idea... the AzureRM.Profile version you are using is too old. Some suggestions:

  1. Get-Module AzureRM.profile -ListAvailable Make sure you've installed only one version
  2. Reinstall AzureRM.profile
  3. Update AzureRM.profile
  4. Switch to Az.Accounts
pritiherkal commented 4 years ago

There 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.

isra-fel commented 4 years ago

You are welcome 😀