locked
Azure Storage Tables issue while working with Azure Powershell version 5.1.1 RRS feed

  • Question

  • Hello,

    When i try to insert an entity in azure storage table using Powershell (v5.1.1) , i get the following error:

    Script
    $entity = New-Object Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity $PartitionKey, $RowKey
    $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::InsertOrMerge($entity))

    Error
    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"."

    Observations 
    As per the release of Azure Powershell version 5.1.1, it has upgraded Azure Storage Client Library 8.6.0.0 (Microsoft.WindowsAzure.Storage.dll) 
    but it also keeping the older version (v8.1.1.0).

    So, there are two libraries with the same name but the different version. The lower version (v8.1.1.0) 
    which is present under C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Storage 
    and the higher version (v8.6.0.0) file present in C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Storage\Azure.Storage

    In order to perform operations on Azure Storage Tables, v8.6.0.0 is the one which is required to deal with all the Azure Storage Table Operations. 
    By default, any object for example like below uses the file located in AzureRm.Storage folder -

    Assembly                                                                                          Module
    --------                                                                                          ------
    Microsoft.WindowsAzure.Storage, Version=8.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.WindowsA...


    • Moved by Nirushi J Monday, January 15, 2018 10:28 AM better suited
    • Edited by Prasad Metkar Tuesday, January 16, 2018 4:17 AM
    Monday, January 15, 2018 9:29 AM

Answers

  • 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"

    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.

    For more details, refer “#5030”.       

    -----------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and “Vote as Helpful” on the post that helps you, this can be beneficial to other community members

    Monday, January 15, 2018 6:55 PM

All replies

  • 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"

    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.

    For more details, refer “#5030”.       

    -----------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and “Vote as Helpful” on the post that helps you, this can be beneficial to other community members

    Monday, January 15, 2018 6:55 PM
  • You can use following function to choose the latest Microsoft.WindowsAzure.Storage (XSCL), then create object by specify the XSCL version.

    Besides that, there are many table manage cmdelts in https://github.com/paulomarquesc/AzureRmStorageTable, it's better if you can use the cmdelts directly instead of new object by yourself.

     

    function GetLatestFullAssemblyName

    {

           param

           (

                 [string]$dllName

           )

     

           # getting list of all assemblies

           $assemblies = [appdomain]::currentdomain.getassemblies() | Where-Object {$_.location -like "*$dllName"}

          

           if ($assemblies -eq $null)

           {

                 throw "Could not identify any assembly related to DLL named $dllName"

           }

     

           $sanitazedAssemblyList = @()

           foreach ($assembly in $assemblies)

           {

                 [version]$version = $assembly.fullname.split(",")[1].split("=")[1]

                 $sanitazedAssemblyList += New-Object -TypeName psobject -Property @{"version"=$version;"fullName"=$assembly.fullname}

           }

     

           return ($sanitazedAssemblyList | Sort-Object version -Descending)[0]

    }

     

    $assemblySN = (GetLatestFullAssemblyName -dllName Microsoft.WindowsAzure.Storage.dll).fullname

     

    $entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $PartitionKey, $RowKey

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

     

    • Proposed as answer by Md Shihab Tuesday, January 16, 2018 3:59 AM
    Tuesday, January 16, 2018 1:50 AM