Azure Storage Table cannot be updated: Cannot convert argument "operation", with value: "Microsoft.WindowsAzure.Storage.Table.TableOperation", for "Execute"
Cmdlet(s)
$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity)) and $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity), [Microsoft.WindowsAzure.Storage.Table.TableRequestOptions]$null, [Microsoft.WindowsAzure.Storage.OperationContext]$null) where $table is of type [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageTable]
PowerShell Version
PSVersion 5.1.14393.1770
OS Version
BuildVersion 10.0.14393.1770 When calling the following update statement for inserting/updating a row in azure table storage
Module Version
Azure.Storage 4.0.0
Description
When we try to update an entity in azure storage table, at random times we get the following error:
Script/Steps for Reproduction
$dataFieldAsJson = $properties.ToString()
$entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" $partitionKey, $rowKey
$entity.Properties.Add("Data", $dataFieldAsJson)
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity))
Debug Output
Cannot find an overload for "Execute" and the argument count: "1".
At Z:\ESNC\IntegrationScripts\ETM-Extend_Threat_Details.ps1:33 char:5
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Stora ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
And if we specify the default parameters we get the following error:
Script/Steps for Reproduction
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity), [Microsoft.WindowsAzure.Storage.Table.TableRequestOptions]$null, [Microsoft.WindowsAzure.Storage.OperationContext]$null)
Debug Output
Cannot convert argument "operation", with value: "Microsoft.WindowsAzure.Storage.Table.TableOperation", for "Execute"
to type "Microsoft.WindowsAzure.Storage.Table.TableOperation": "Cannot convert the
"Microsoft.WindowsAzure.Storage.Table.TableOperation" value of type
"Microsoft.WindowsAzure.Storage.Table.TableOperation" to type "Microsoft.WindowsAzure.Storage.Table.TableOperation"."
At MyScript.ps1:33 char:5
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Stora ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
@etm-admin This appears to be using the azure storage sdk and not the powershell storage cmdlets. Please file this issue against the storage sdk.
@etm-admin It seems you meet same issue as : https://github.com/Azure/azure-powershell/issues/5030
A workaround is specify the version to be aligned with PowerShell Azure.Storage module when new the object:
$temp = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.WindowsAzure.Storage, Version=8.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
please note, in latest PowerShell 5.1.1, it will be 8.6.0; in the before PowerShell version, the Microsoft.WindowsAzure.Storage version is different.
@blueww With this workaround I get the following error:
##[error]Cannot convert argument "entity", with value: "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity", for "InsertOrReplace" to type "Microsoft.WindowsAzure.Storage.Table.ITableEntity": "Cannot convert the "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" value of type "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" to type "Microsoft.WindowsAzure.Storage.Table.ITableEntity"."
My code looks like:
$assemblySN = (GetLatestFullAssemblyName -dllName Microsoft.WindowsAzure.Storage.dll).fullname
Write-Host "assemblysn: $assemblySN"
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $PartitionKey, $RowKey
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrReplace($entity))
Am I doing something wrong?