5

I just moved a function from an MVC App to an MVC API App, and for some reason it all works except CloudTable.Execute.

Code:

try
            {
                CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
        "accountName",
        "key"), true);

                CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
                CloudTable table = cloudTableClient.GetTableReference("SkypeUsers");
                table.CreateIfNotExistsAsync();

                TableOperation retrieveOperation = TableOperation.Retrieve<WorkUser>("Skype", skypeid);
                TableResult retrievedResult = table.Execute(retrieveOperation); //Does not work

                retrievedSkypeId = ((WorkUser)retrievedResult.Result).RowKey;
            }
            catch (Exception ex)
            {

            }

Error:

Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no 
extension method 'Execute' accepting a first argument of type 'CloudTable' could 
be found (are you missing a using directive or an assembly reference?)

The reference to Microsoft.WindowsAzure.Storage is the same version I use in my App. Ive tried cleaning and re-building. Not sure what the issue is.

EDIT:

Print of my only Execute-options: enter image description here

Green_qaue
  • 3,561
  • 11
  • 47
  • 89

2 Answers2

6

I am targeting .NET Core & using assembly Microsoft.WindowsAzure.Storage, Version=9.2.0.0. The ExecuteQuery does not exist within CloudTable for this version. This might be your case as well.

Use:

table.ExecuteQuerySegmentedAsync(query, null).Result;

The ExecuteQuery sync is still available for .NET Framework version however for NET Standard use ExecuteQuerySegmentedAsync instead.

meistars
  • 73
  • 1
  • 7
  • 5
    While this line of code might answer the question you still might consider adding a few explanatory sentences as this increases the value of your answer for other users. – MBT Jun 08 '18 at 14:12
  • It might be good to note that in general case, you might need to iterate execution as in https://stackoverflow.com/questions/24234350/how-to-execute-an-azure-table-storage-query-async-client-version-4-0-1 – ovolko Mar 25 '19 at 19:30
  • 1
    Great answer.. Documentation is all for older version. But never use .Result.. instead use await table.ExecureQuerySegmentedAsync – Tim Davis Nov 03 '21 at 04:09
1

Error CS1061 'CloudTable' does not contain a definition for 'Execute' and no extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)

CloudTable.Execute Method (TableOperation, TableRequestOptions, OperationContext) accepts a TableOperation object as the first argument, and according to the code you provide, we could find you indeed pass a TableOperation object to Execute method, it should not return the error. Please try to install the latest version Microsoft Azure Storage Client Library for .NET to your project (the code works fine with WindowsAzure.Storage v8.0.0 on my side) and test if same issue will appear. You could also tell us the version of WindowsAzure.Storage you are using now, and then we will test the code with that version.

Besides, please try to use TableQuery to generate a query and call CloudTable.ExecuteQuery method to retrieve the entity.

TableQuery<WorkUser> query = new TableQuery<WorkUser>().Where(
    TableQuery.CombineFilters(
        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Skype"),
        TableOperators.And,
        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, skypeid)));

retrievedSkypeId = table.ExecuteQuery(query).FirstOrDefault().RowKey;
Fei Han
  • 26,415
  • 1
  • 30
  • 41