Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function to Update Table Storage entity - CloudTable.Execute not found

I'm starting out using Azure and c# and I'm attempting to use Table Storage - and using an Azure Function to update entitys in the table. My code is as follows:

 #r "Microsoft.WindowsAzure.Storage"
#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json; 
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;

public static async Task<HttpResponseMessage> Run(HttpRequest req, CloudTable lookupTable)
{
    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    string partitionKey = data.Society;
    string rowKey = data.ConnectionDetails.Environment; 
    string newConnection = data.ConnectionDetails.Connection; 

    TableOperation operation = TableOperation.Retrieve<SocietyConnectionDetails>(partitionKey, rowKey); 
    TableResult result = lookupTable.Execute(operation);
    SocietyConnectionDetails societyConnectionDetails = (SocietyConnectionDetails)result.Result; 

    societyConnectionDetails.Connection = newConnection; 
    operation = TableOperation.Replace(societyConnectionDetails); 
    lookupTable.Execute(operation);
}

public class SocietyConnectionDetails : TableEntity
{
    public string Connection {get; set;}
}

But the errors im getting are as follows:

2020-02-25T10:33:16.956 [Error] run.csx(17,38): error CS1061: 'CloudTable' does not contain a definition for 'Execute' and no accessible extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
2020-02-25T10:33:16.984 [Error] run.csx(22,17): error CS1061: 'CloudTable' does not contain a definition for 'Execute' and no accessible extension method 'Execute' accepting a first argument of type 'CloudTable' could be found (are you missing a using directive or an assembly reference?)
2020-02-25T10:33:17.011 [Error] run.csx(8,47): error CS0161: 'Run(HttpRequest, CloudTable)': not all code paths return a value

I can see that the issue is happening when im attempting to 'Execute' my Table Operations... this might be a relatively straight forward problem but I'm struggling to work out why this wouldn't be working...

Thanks for any help..

like image 821
CJL1992 Avatar asked Sep 15 '26 19:09

CJL1992


1 Answers

I can reproduce your error.

Like this:

enter image description here

Solution is add a function.proj file to your function. enter image description here

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    </ItemGroup>
</Project>

Then the error should disappear. (If you dont do this. the compilation step will not success.) enter image description here

like image 98
Cindy Pau Avatar answered Sep 18 '26 11:09

Cindy Pau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!