3

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

1
  • From your description, you are using crx. So you need to add a file to install the assembly. Commented Feb 25, 2020 at 11:57

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks a lot - I've added the function.csproj file but unfortunately still getting the came error. Basically its giving me what you have in the last image above then this: 2020-02-25T12:41:17.936 [Information] D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.0. Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.0. [D:\local\Temp\e0310930-cfd5-4e9b-8991-6a8e0c468f04\function.proj]
And then compilation errors: 2020-02-25T12:41:18.292 [Error] run.csx(24,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-25T12:41:18.320 [Error] run.csx(10,47): error CS0161: 'Run(HttpRequest, CloudTable)': not all code paths return a value 2020-02-25T12:41:18.349 [Error] Executed 'Functions.HttpLookUpUpdate' (Failed, Id=90b0193c-bccb-41a6-8acd-2359bcaa1ac4)
@CJL1992 Change the TargetFramework to netcoreapp2.2.
Cheers, I changed it there now and it has created the projects.assets.json etc. Only issues now are the compilation errors above
Let me know if you have any ideas about what might be causing the compilation errors - please
|
1

I assume you are using the Azure Functions runtime 2, and in this case the problem is related to your references. You should reference the nuget package Microsoft.Azure.WebJobs.Extensions.Storage and ensure it is installed in your function, according to this article in Microsoft's documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.