Harshith R
Harshith R

Reputation: 448

Cannot find an overload for "Execute" and the argument count: "1". unable to insert into azure storage table

I have a powershell script to upload data into azure storage table. Powershell script looks like this:


$StorageAccountName = "xxx" 
$StorageAccountKey = "xxxxx"
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tableName = "ProvisioningRecord"
$table = Get-AzStorageTable –Name $tableName -Context $ctx

Add-Entity -table $table -partitionKey abc -rowKey xyz


function Add-Entity { 
   [CmdletBinding()] 

   param( 
      $table, 
      [String]$partitionKey, 
      [String]$rowKey 

   )  


   $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" -ArgumentList $partitionKey, $rowKey 

   $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity)) 

}

I get the error:

Cannot find an overload for "Execute" and the argument count: "1".
At line:1 char:1
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Following this link: https://www.catapultsystems.com/blogs/azure-storage-powershell-error-cannot-find-an-overload/ i added

$assemblySN = $table.CloudTable.GetType().Assembly.FullName
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::InsertOrReplace(`$entity)"))

It gives me an error:

New-Object : Cannot find type [Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.Azure.Cosmos.Table, Version=0.10.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]: 
verify that the assembly containing this type is loaded.
At line:1 char:11
+ $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table. ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

But the same code with the above modifications(adding $assemblySN) works in Powershell version 5.1.17134.590. Same script does't work in Powershell version 5.1.17763.316.

Can anybody help me with this?

Upvotes: 0

Views: 1354

Answers (1)

Wei Wei -Microsoft
Wei Wei -Microsoft

Reputation: 556

Which version of Az.Storage module do you use? (run Get-module to check).

From Az.Storage 1.1.0, table is managed with Microsoft.Azure.Cosmos.Table SDK. (since new storage client library not support table anymore.)

So the namespace for Azure Table objects are changed from "Microsoft.WindowsAzure.Storage.Table" to "Microsoft.Azure.Cosmos.Table". And you need the change the namespace in your script accordingly.

See more detail in https://github.com/Azure/azure-powershell/issues/8808

Upvotes: 1

Related Questions