Search code examples
azureazure-functionsnamespaces.net-8.0azure-functions-isolated

Namespace 'BlobOutputAttribute' not found in new Azure Functions Core project


I just created my first project with Azure Functions Core, and I'm unable to set an output binding to blob storage on my function. This is .NET 8 in an isolated process.

Here is the code - it's a variation on a tutorial found here:

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace client
{
    public class GetTest
    {
        private readonly ILogger _logger;

        public GetTest(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<GetTest>();
        }

        [Function("GetTest")]
        [BlobOutput("test-samples-output/{rand-guid}.txt")] //NAMESPACE NOT FOUND ERROR
        public string Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");

            return "blob written successfully!";
        }
    }
}

In VSCode, an error appears over the 'BlobOutput' attribute, saying its type or namespace is not present. However, Microsoft.Azure.Functions.Worker and Microsoft.Azure.Functions.Worker.Extensions are both declared. What am I missing?


Solution

  • To fix this error, from the VSCode terminal I ran this:

    dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage
    

    It is worth noting that I don't need 'using Microsoft.Azure.Functions.Worker.Extensions' at the top anymore, VSCode is able to detect the namespace correctly without it.