Reputation: 111
Hi I am trying out simple Azure Function with REST Api. My env is MSVC 2019 and created a simple mmApi Fucntion app
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using AzureFuncApp.Model;
using System.Collections.Generic;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage;
namespace AzureFuncApp
{
public static class mmApi
{
//static List<Board> boards = new List<Board>();
[FunctionName("CreateBoard")]
public static async Task<IActionResult> CreateBoard(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "board")] HttpRequest req,
[Table("boards", Connection ="AzureWebJobsStorage")] IAsyncCollector<BoardTableEntity> boardTable,
ILogger log)
{
log.LogInformation("Creating a new board.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var input = JsonConvert.DeserializeObject<BoardCreateModel>(requestBody);
var board = new Board() { PlayerCount = input.PlayerCount };
board.Players.Add(input.Player);
await boardTable.AddAsync(board.ToTableEntity());
return new OkObjectResult(board);
}
It is this line that I have added to Table Storage [Table("boards", Connection ="AzureWebJobsStorage")] IAsyncCollector
Is throwing the below error
Function (AzureFuncAppmmApi/CreateBoard) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'CreateBoard'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'boardTable' to type IAsyncCollector`1. 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.).
What I am not following is where do I register builder.AddAzureStorage() when I don't have the startup file in my project.
Attached is my project details, any help and pointer is appriciated
Upvotes: 0
Views: 243
Reputation: 111
I found the answer, Microsoft.NET.Sdk.Functions updates to v3.0.2, manually added the below refrences in the csprog file and it works fine. @tubakaya your suggestion helped
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.23" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.1" /> </ItemGroup>```
Upvotes: 1