locked
Writing to a storage Queue from a Powershell Automation Runbook intermittently fails with Cannot find an overload for "AddMessage" RRS feed

  • Question

  • The following code intermittently fails with the below message

    $ctx = New-AzureStorageContext -StorageAccountName $storageacnt -StorageAccountKey $key -Environment AzureUSGovernment
    $queue = Get-AzureStorageQueue –Name $queueName –Context $ctx
    $queueMessage = New-Object -TypeName Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage -ArgumentList "This is message 1"
    $queue.CloudQueue.AddMessage($QueueMessage)  
    

    Cannot find an overload for "AddMessage" and the argument count: "1".
    At line:4 char:1
    + $queue.CloudQueue.AddMessage($QueueMessage)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
     


     
    Tuesday, January 23, 2018 12:18 AM

Answers

  • I received the same error when using the sample code from Microsoft's documentation:

    Perform Azure Queue storage operations with Azure PowerShell

    After a couple of hours of search and experimentation, rather than creating a $queueMessage object, I simply passed the string as the argument.  The following worked, placing a message on the $queueName: 

    $queue.CloudQueue.AddMessage("This is Message 1")


    • Marked as answer by learningmind Thursday, March 22, 2018 10:16 PM
    Wednesday, March 21, 2018 8:52 PM

All replies

  • Any suggestions
    Thursday, January 25, 2018 12:35 AM
  • I have changed my code to the following but still receive the same error.

    param(
      [string]
     $storageAccountName = "teststorageaccount",
    
      [string]
     $resourceGroupName = "testresourcegroup",
    
      [string]
     $queueName = "test-queue",
    
      [string]
     $message = "This is a sample message"
    
    )
    
    
    $connectionName = "AzureRunAsConnection"
    
    try{
        $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
        Add-AzureRmAccount -ServicePrincipal -TenantId $servicePrincipalConnection.TenantId -ApplicationId $servicePrincipalConnection.ApplicationId -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint -EnvironmentName AzureUSGovernment
        $StorageKey = Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroupName
        $ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $StorageKey[0].Value -EnvironmentName AzureUSGovernment 
        $queue = Get-AzureStorageQueue –Name $queueName –Context $ctx
        $queueMessage = New-Object -TypeName Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage -ArgumentList $message
        $queue.CloudQueue.AddMessage($QueueMessage)
    }catch{
     if (!$servicePrincipalConnection)
        {
            $ErrorMessage = "Connection $connectionName not found."
            throw $ErrorMessage
        } else{
            Write-Error -Message $_.Exception
            throw $_.Exception
        }
    }
    

    it gives me the following error

     : System.Management.Automation.MethodException: Cannot find an overload for "AddMessage" and the argument count: "1".
       at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception 
    exception)
       at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
        + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
    

    Wednesday, January 31, 2018 2:47 PM
  • How often do you see the error? Are you running a lot of these automation jobs in parallel or do these run sequentially? You might be running into memory constraints on the sandbox which might given this error depending how many jobs you are running.

    Thanks,

    Eamon


    This posting is provided AS IS with no warranties, and confers no rights.

    • Proposed as answer by Femisulu-MSFT Sunday, February 25, 2018 2:30 AM
    Thursday, February 22, 2018 10:53 PM
  • Thank you Eamon. I was testing the write to queue functionality from a run book and hence currently it is adhoc. I tried it multiple times but it still gives me the same error. We have a subscription (not free) account and have sufficient memory too

    Wednesday, March 14, 2018 7:47 PM
  • I received the same error when using the sample code from Microsoft's documentation:

    Perform Azure Queue storage operations with Azure PowerShell

    After a couple of hours of search and experimentation, rather than creating a $queueMessage object, I simply passed the string as the argument.  The following worked, placing a message on the $queueName: 

    $queue.CloudQueue.AddMessage("This is Message 1")


    • Marked as answer by learningmind Thursday, March 22, 2018 10:16 PM
    Wednesday, March 21, 2018 8:52 PM
  • Thank you 70sGeek. That seem to have solved my issue too.
    Thursday, March 22, 2018 10:16 PM