Azure / Azure/azure-powershell

Seeing intermittent error: 'The given key 'Az.MODULE_NAME' was not present in the dictionary.'

Open
#15,882 11 comments 0 reactions 1 assignee Claimed by @VeryEarly View on GitHub
Accounts customer-reported Investigate :mag: needs-team-attention question
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

## Description
We use PowerShell and the Az module to deploy our services to Azure, running off a docker image via Azure Container Instances, and since updating our image around July 14th we have been seeing this error mentioned in the title intermittently during our deployments. We have been able use an older image which works fine that was build on June 7th, but any newer images we try to build have this problem, with the latest versions of PowerShell and Az. Our deployments will be proceeding fine, then a command (such as Set-AzWebapp) will fail with the message regarding the module the command is in, in this case: `The given key 'Az.Websites' was not present in the dictionary.`
We have seen this error mention multiple modules:
* Accounts
* EventGrid
* KeyVault
* Monitor
* Storage
* Websites

Error messages appear as below:
```
Running (New-AzStorageContext) failed
Provided parameters:
-ConnectionString: DefaultEndpointsProtocol=https;AccountName=****;AccountKey=****;EndpointSuffix=core.windows.net
Exception type: System.Collections.Generic.KeyNotFoundException
Exception message: The given key 'Az.Storage' was not present in the dictionary.
```

I have verified this does not seem to be an issue with ACI specifically, as I have also built and run the image locally and see the same error come up.

## Steps to reproduce
Build a docker image based on `jenkins/inbound-agent:4.9-1`, and install PowerShell 7.1.3, and Az 6.3.0.
Use the docker image to run a long, automated deployment with multiple threads and eventually the error message above will come up.

## Environment data

```
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Linux 4.15.0-1113-azure #126~16.04.1-Ubuntu SMP…
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

## Module versions

```powershell
Directory: /usr/local/share/powershell/Modules

ModuleType Version PreRelease Name PSEdition
---------- ------- ---------- ---- ---------
Script 6.3.0 Az Core,Desk
Script 2.5.2 Az.Accounts Core,Desk
Script 1.1.1 Az.Advisor Core,Desk
Script 2.3.0 Az.Aks Core,Desk
Script 1.1.4 Az.AnalysisServices Core,Desk
Script 2.2.0 Az.ApiManagement Core,Desk
Script 1.0.0 Az.AppConfiguration Core,Desk
Script 1.2.0 Az.ApplicationInsights Core,Desk
Script 1.7.0 Az.Automation Core,Desk
Script 3.1.0 Az.Batch Core,Desk
Script 2.0.0 Az.Billing Core,Desk
Script 1.7.1 Az.Cdn Core,Desk
Script 1.9.0 Az.CognitiveServices Core,Desk
Script 4.16.0 Az.Compute Core,Desk
Script 2.1.0 Az.ContainerInstance Core,Desk
Script 2.2.3 Az.ContainerRegistry Core,Desk
Script 1.3.0 Az.CosmosDB Core,Desk
Script 1.1.0 Az.DataBoxEdge Core,Desk
Script 1.1.0 Az.Databricks Core,Desk
Script 1.13.1 Az.DataFactory Core,Desk
Script 1.0.2 Az.DataLakeAnalytics Core,Desk
Script 1.3.0 Az.DataLakeStore Core,Desk
Script 1.0.0 Az.DataShare Core,Desk
Script 1.1.0 Az.DeploymentManager Core,Desk
Script 3.0.0 Az.DesktopVirtualization Core,Desk
Script 1.0.2 Az.DevTestLabs Core,Desk
Script 1.1.2 Az.Dns Core,Desk
Script 1.3.0 Az.EventGrid Core,Desk
Script 1.8.0 Az.EventHub Core,Desk
Script 1.8.0 Az.FrontDoor Core,Desk
Script 3.1.0 Az.Functions Core,Desk
Script 4.3.0 Az.HDInsight Core,Desk
Script 1.3.1 Az.HealthcareApis Core,Desk
Script 2.7.3 Az.IotHub Core,Desk
Script 3.4.5 Az.KeyVault Core,Desk
Script 2.0.0 Az.Kusto Core,Desk
Script 1.5.0 Az.LogicApp Core,Desk
Script 1.1.3 Az.MachineLearning Core,Desk
Script 1.1.1 Az.Maintenance Core,Desk
Script 2.0.0 Az.ManagedServices Core,Desk
Script 1.0.2 Az.MarketplaceOrdering Core,Desk
Script 1.1.1 Az.Media Core,Desk
Script 1.1.0 Az.Migrate Core,Desk
Script 2.7.0 Az.Monitor Core,Desk
Script 4.10.0 Az.Network Core,Desk
Script 1.1.1 Az.NotificationHubs Core,Desk
Script 2.3.0 Az.OperationalInsights Core,Desk
Script 1.4.1 Az.PolicyInsights Core,Desk
Script 1.1.2 Az.PowerBIEmbedded Core,Desk
Script 1.0.3 Az.PrivateDns Core,Desk
Script 4.4.0 Az.RecoveryServices Core,Desk
Script 1.5.0 Az.RedisCache Core,Desk
Script 1.0.0 Az.RedisEnterpriseCache Core,Desk
Script 1.0.3 Az.Relay Core,Desk
Script 1.0.0 Az.ResourceMover Core,Desk
Script 4.3.0 Az.Resources Core,Desk
Script 1.0.0 Az.Security Core,Desk
Script 1.0.0 Az.SecurityInsights Core,Desk
Script 1.5.0 Az.ServiceBus Core,Desk
Script 3.0.1 Az.ServiceFabric Core,Desk
Script 1.3.0 Az.SignalR Core,Desk
Script 3.4.1 Az.Sql Core,Desk
Script 1.1.0 Az.SqlVirtualMachine Core,Desk
Script 3.10.0 Az.Storage Core,Desk
Script 1.5.0 Az.StorageSync Core,Desk
Script 2.0.0 Az.StreamAnalytics Core,Desk
Script 1.0.0 Az.Support Core,Desk
Script 1.0.4 Az.TrafficManager Core,Desk
Script 2.8.1 Az.Websites Core,Desk
Script 5.3.0 Pester Desk
Script 4.6.0 Posh-ACME Core,Desk

Directory: /opt/microsoft/powershell/7/Modules

ModuleType Version PreRelease Name PSEdition
---------- ------- ---------- ---- ---------
Manifest 1.2.5 Microsoft.PowerShell.Archive Desk
Manifest 7.0.0.0 Microsoft.PowerShell.Host Core
Manifest 7.0.0.0 Microsoft.PowerShell.Management Core
Manifest 7.0.0.0 Microsoft.PowerShell.Security Core
Manifest 7.0.0.0 Microsoft.PowerShell.Utility Core
Script 1.4.7 PackageManagement Desk
Script 2.2.5 PowerShellGet Desk
Script 2.0.5 PSDesiredStateConfiguration Core
Script 2.1.0 PSReadLine Desk
Binary 2.0.3 ThreadJob Desk
```

## Debug output

```
Running New-AzStorageContext
DEBUG: 7:23:40 PM - NewAzureStorageContext begin processing with ParameterSet 'ConnectionString'.
New-AzStorageContext failed after 0.5169169 seconds
Running (New-AzStorageContext) failed
Provided parameters:
-ConnectionString: DefaultEndpointsProtocol=https;AccountName=****;AccountKey=****;EndpointSuffix=core.windows.net
Exception type: System.Collections.Generic.KeyNotFoundException
Exception message: The given key 'Az.Storage' was not present in the dictionary.
```

## Error output

```
Running (Set-AzWebApp) failed
Provided parameters:
-ResourceGroupName: ****-rg -AppSettings: System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry -Name: ****-wapp
Exception type: System.Collections.Generic.KeyNotFoundException
Exception message: The given key 'Az.Websites' was not present in the dictionary.
Entered Has-ErrorMessage
DEBUG: 5:22:55 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 5:22:55 AM - using account id ****...
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.

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

DEBUG: AzureQoSEvent: Module: Az.Accounts:2.5.2; CommandName: Resolve-AzError; PSVersion: 7.1.3; IsSuccess: True; Duration: 00:00:00.3673249
DEBUG: Finish sending metric.
DEBUG: 5:22:56 AM - ResolveError end processing.
Entered Has-ErrorMessage
Entered Has-ErrorMessage
Checking for Retry-After header.
Error does not have exception and/or exception response.
Set-AzWebApp: The given key 'Az.Websites' was not present in the dictionary.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.