1
votes

I have this azure function v3:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.Cosmos.Table;

namespace FunctionApp4
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            [Table("Items")] CloudTable table,
            ILogger log)
        {
            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);
        }
    }
}

Runs perfectly locally but when published to the portal I get:

Error indexing method 'Function1' Cannot bind parameter 'table' to type CloudTable. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Does anyone know what could be causing this?

These are the dependencies for the function:

preview

Setup seems ok, try installing 1.0.8 of Microsoft.Azure.Cosmos.Tableuser1672994
The code looks like it's targeting the .net core in-process model, but the error message sounds like it's expecting a .net 5 out-of-process model. Which one are you trying to do?Stephen Cleary
@StephenCleary it's just the default setup. Nothing specified in the project file so I think that means it's running out of process. In what way does "the code looks like it's targeting the .net core in-process model"? The targetframework is netcoreapp3.1.CraftyFox
What's your configuration? Have you got a storage connection string set up in your deployed function?Stephen Cleary
@StephenCleary in Applications settings of the portal I had the connectionstring setting under 'AzureWebJobsStorage'CraftyFox