Where is updated documentation to make an Azure Function C# script use CloudTable as an input?

Viewed 237

I'm working on creating a Proof-Of-Concept Azure Function using C# script. that needs to talk to an Azure Storage Table.

I followed the instructions at Azure Table storage input bindings for Azure Functions and I get an error saying "Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable".

In my research I've found that the example in the document is out of date anyways and that I should be using a different set of namespaces. Yet I cannot find examples, documentation, or even blog posts talking about how to consume the correct namespaces. In fact, everything I've found online just says that my code should "just work".

Here's the code that currently won't even compile:

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using Microsoft.WindowsAzure.Storage.Table;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log, CloudTable releasebranchtable)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    string responseMessage = string.IsNullOrEmpty(name)
        ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
}

Here's my csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
    <None Update="HttpTrigger2/run.csx">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="HttpTrigger2/function.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Here's the bindings (though generated by Azure I think):

{
   "name": "releasebranchtable",
   "tableName": "MyTable",
   "connection": "AzureWebJobsStorage",
   "direction": "in",
   "type": "table"
}

Do updated docs or complete examples even exist? I feel like I've searched everywhere and have come up empty.

1 Answers

I tried to reproduce the issue with .Net 6 - v4 and v3 stack in Azure Functions:

  1. Table Attribute didn't work with version 5.0.0 Microsoft.Azure.WebJobs.Extensions.Storage but worked with 4.0.5 in both v3 and v4.

enter image description here

Note:

As I can see from the NuGet Package Site, WindowsAzure.Storage is deprecated and its final version is 9.3.3. It has been replaced by the Azure.Storage.Blobs

The Microsoft.Azure.Cosmos.Table SDK implements the Table API which both Azure Storage Tables and Azure CosmosDB Table API support. The SDK adapts based on the service connecting to. Therefore the Microsoft.Azure.WebJobs.Extensions.Storage SDK references Microsoft.Azure.Cosmos.Table instead.

Updated Answer:

I have checked in the C# Script Azure Function Project, it works as expected for version 4.0.5 Microsoft.Azure.WebJobs.Extensions.Storage.

enter image description here

Related