Azure functions isolated-process BlobTrigger not firing

343 views Asked by At

I have the following Function (BlobTrigger) running as an isolated process (net8). Its failing to trigger when I upload a file to the storage account. I’m not sure why its not triggering. Any help would be appreciated.

[Function(nameof(ProcessData))]
[StorageAccount("StorageAccountConnectionString")]
public async Task Run([BlobTrigger("%MyDirectory%/{filename}")] 
    Stream jsonBlob, string filename)
{
    logger.LogInformation($"Triggered for file {filename}");
}

local.settings.json

    {
  "IsEncrypted": false,
  "Values": {
    "StorageAccountConnectionString": "DefaultEndpointsProtocol=https;AccountName=*****",
    "MyDirectory": "container/folder1",
            }
   } 

Libraries

    <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
          <OutputType>Exe</OutputType>
    ...
    ...
       
     <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
3

There are 3 answers

2
GRoberts On

I found that setting up the Function to use the Connection parameter of the BlobTrigger attribute rather than decorating the method with the StorageAccount attribute worked for me.

[Function(nameof(ProcessData))]
public async Task Run(
    [BlobTrigger("%MyDirectory%/{filename}",
        Connection = "StorageAccountConnectionString")] 
    Stream jsonBlob, string filename)
{
    logger.LogInformation($"Triggered for file {filename}");
}
0
Pavan On

I have created a blob-trigger function with the runtime stack .NET 8.0.

I am able to trigger the function when uploading the blob into the container. Below is my code:

.csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

function code:

using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace Company.Function
{
    public class BlobTrigger10
    {
        private readonly ILogger<BlobTrigger10> _logger;

        public BlobTrigger10(ILogger<BlobTrigger10> logger)
        {
            _logger = logger;
        }

        [Function(nameof(BlobTrigger10))]
        public async Task Run([BlobTrigger("pavan/sample.txt", Connection = "AzureWebJobsStorage")] Stream stream, string name)
        {
            using var blobStreamReader = new StreamReader(stream);
            var content = await blobStreamReader.ReadToEndAsync();
            _logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name} \n Data: {content}");
        }
    }
}

program.cs:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

I have uploaded the blob into the container in the Azure portal, as shown below:

enter image description here

After uploading the blob in the container, it gets triggered. See below:

enter image description here

0
DomV3 On

I was having a similar issue in a .Net 8 Blob Trigger. It came back saying that cannot convert 'stream' to System.IO.Stream. The error right after that was saying that it could not find my storage connection string although it was defined in my user secrets. It needs to also be defined in your program.cs. Once I added user secrets there I never got an error relating to conversion again. Here's what I added to fix my issue.

    .ConfigureAppConfiguration(config =>
{
    config.AddUserSecrets<YourFunctionHere>(optional: true, reloadOnChange: false);
})