Storage queues: AddMessageAsync fails with MethodCountCouldNotFindBest
Description
On a fresh install of PowerShell Core 6.2 and the Az module, I am getting conflicts between assembly versions of the Storage client libraries.
This prevents running the example to add a message to a queue in https://docs.microsoft.com/en-us/azure/storage/queues/storage-powershell-how-to-use-queues#add-a-message-to-a-queue. I have found a workaround by passing a fully qualified assembly/type name to New-Object but this was not obvious so I thought I'd log in case others get this too.
Steps to reproduce
Repro:
Connect-AzAccount
Set-AzContext -SubscriptionName "My subscription"
$ctx = (Get-AzStorageAccount -ResourceGroupName my-resource-group -Name mystorageaccount).Context
$queue = Get-AzStorageQueue -Context $ctx -Name myqueue
$msg = New-Object -TypeName Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage -ArgumentList "test"
$queue.CloudQueue.AddMessageAsync($msg)
This produces a MethodCountCouldNotFindBest error: Cannot find an overload for "AddMessageAsync" and the argument count: "1"..
The issue is mismatched versions of the storage client library:
PS > $msg.GetType().Assembly.Location
C:\Users\me\Documents\PowerShell\Modules\Az.Accounts\1.4.0\Microsoft.WindowsAzure.Storage.dll
PS > $queue.CloudQueue.GetType().Assembly.Location
C:\Users\me\Documents\PowerShell\Modules\Az.Storage\1.1.0\Microsoft.Azure.Storage.Queue.dll
I have a successful workaround by instead using New-Object -TypeName "Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage,Microsoft.Azure.Storage.Queue, Version=9.4.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" to create the message.
Environment data
Name Value
---- -----
PSVersion 6.2.0
PSEdition Core
GitCommitId 6.2.0
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Script 1.4.0 Az.Accounts Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosa…
Script 1.0.1 Az.Aks Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksC…
Script 1.0.2 Az.AnalysisServices Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnalys…
Script 1.0.0 Az.ApiManagement Core,Desk {Add-AzApiManagementRegion, Get-AzApiManagementSso…
Script 1.0.0 Az.ApplicationInsights Core,Desk {Get-AzApplicationInsights, New-AzApplicationInsig…
Script 1.2.0 Az.Automation Core,Desk {Get-AzAutomationHybridWorkerGroup, Remove-AzAutom…
Script 1.0.0 Az.Batch Core,Desk {Remove-AzBatchAccount, Get-AzBatchAccount, Get-Az…
Script 1.0.0 Az.Billing Core,Desk {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-Az…
Script 1.1.0 Az.Cdn Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzC…
Script 1.0.1 Az.CognitiveServices Core,Desk {Get-AzCognitiveServicesAccount, Get-AzCognitiveSe…
Script 1.6.0 Az.Compute Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, …
Script 1.0.0 Az.ContainerInstance Core,Desk {New-AzContainerGroup, Get-AzContainerGroup, Remov…
Script 1.0.1 Az.ContainerRegistry Core,Desk {New-AzContainerRegistry, Get-AzContainerRegistry,…
Script 1.0.2 Az.DataFactory Core,Desk {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-…
Script 1.0.0 Az.DataLakeAnalytics Core,Desk {Get-AzDataLakeAnalyticsDataSource, New-AzDataLake…
Script 1.1.0 Az.DataLakeStore Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDa…
Script 1.0.0 Az.DevTestLabs Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutd…
Script 1.0.0 Az.Dns Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove…
Script 1.1.0 Az.EventGrid Core,Desk {New-AzEventGridTopic, Get-AzEventGridTopic, Set-A…
Script 1.0.1 Az.EventHub Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNamespace,…
Script 1.0.0 Az.HDInsight Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefini…
Script 1.0.2 Az.IotHub Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGrou…
Script 1.1.0 Az.KeyVault Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCerti…
Script 1.2.1 Az.LogicApp Core,Desk {Get-AzIntegrationAccountAgreement, Get-AzIntegrat…
Script 1.0.0 Az.MachineLearning Core,Desk {Move-AzMlCommitmentAssociation, Get-AzMlCommitmen…
Script 1.0.0 Az.MarketplaceOrdering Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script 1.0.0 Az.Media Core,Desk {Sync-AzMediaServiceStorageKeys, Set-AzMediaServic…
Script 1.0.1 Az.Monitor Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLo…
Script 1.6.0 Az.Network Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate…
Script 1.0.0 Az.NotificationHubs Core,Desk {Get-AzNotificationHub, Get-AzNotificationHubAutho…
Script 1.1.0 Az.OperationalInsights Core,Desk {New-AzOperationalInsightsAzureActivityLogDataSour…
Script 1.0.0 Az.PolicyInsights Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolic…
Script 1.0.0 Az.PowerBIEmbedded Core,Desk {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerB…
Script 1.2.0 Az.RecoveryServices Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRecov…
Script 1.0.0 Az.RedisCache Core,Desk {Remove-AzRedisCachePatchSchedule, New-AzRedisCach…
Script 1.0.0 Az.Relay Core,Desk {New-AzRelayNamespace, Get-AzRelayNamespace, Set-A…
Script 1.2.1 Az.Resources Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment,…
Script 1.0.0 Az.ServiceBus Core,Desk {New-AzServiceBusNamespace, Get-AzServiceBusNamesp…
Script 1.0.1 Az.ServiceFabric Core,Desk {Add-AzServiceFabricApplicationCertificate, Add-Az…
Script 1.0.2 Az.SignalR Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, N…
Script 1.7.0 Az.Sql Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get-A…
Script 1.1.0 Az.Storage Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, Ne…
Script 1.0.0 Az.StreamAnalytics Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyt…
Script 1.0.1 Az.TrafficManager Core,Desk {Add-AzTrafficManagerCustomHeaderToEndpoint, Remov…
Script 1.1.2 Az.Websites Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-A…
@blueww Hey Wei, would you mind taking a look at this issue?
@hoppyluke Thanks for reporting the issue! In my testing, seems this only happen on Powershell 6.*, but not in Powershell 5.1.
Actually, we need to keep the queue message object and queue object are created from same version of Client Library, so we can change command like following , to make it works on any version of Client library (when namespace is same):
New-Object -TypeName "Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage,$($queue.CloudQueue.GetType().Assembly.FullName)" -ArgumentList "test"
The issue might can be resolved after upgrade to a future release Storage Client library (Microsoft.Azure.Storage.Queue/Blob/File). Will update the issue when get any progress.
Anyway, the doc will also need update after the change.
@hoppyluke the doc is already updated for the issue. So I will close the issue now.
Feel free to contact us if you need any further assistant.
I ran into this issue too a few days back. IMHO, having types with the same fully-qualified name defined in two assemblies is simply wrong. Is there a plan to resolve this root cause in future releases?
@daxian-dbw This should already be resolved in the new released Az 2.0.0. The namespace is changed to "Microsoft.Azure.Storage.Queue.CloudQueueMessage" in the new release.
So the usage will like following, and there will be no conflict. (I would still suggest adding Assembly.FullName to the TypeName, but it will also work without adding it in Az 2.0.0)
$queue = Get-AzStorageQueue –Name $queueName –Context $ctx
$queueMessage = New-Object -TypeName "Microsoft.Azure.Storage.Queue.CloudQueueMessage" -ArgumentList "This is message 1"
$queue.CloudQueue.AddMessageAsync($QueueMessage)
That's great! Thanks @blueww for the update.