Search code examples
asp.net-mvcasp.net-web-apireferenceazure-storage

CloudTable.Execute not working in API


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


Solution

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