azure-functions.net-8.0azure-blob-triggerazure-functions-isolateddotnet-isolated

.NET 8 ISOLATED Azure Function - Binding attributes not working


I am porting an old .NET 6 in-process Azure Function app, to .NET 8 isolated worker model. I have an issue where it seems like the app configuration expression resolution for our Azure Function bindings no longer works in .NET 8 isolated.

For instance, this BlobTrigger function used to look like this with .NET 6 in-process:

public async Task Run([BlobTrigger(
    "%StorageContainer:SourceImages%/{name}")]
BlobClient blob)

We had an app setting for %StorageContainer:SourceImages% in local.settings.json:

...
"StorageContainer:SourceImages": "mycontainer",
....

The blob trigger would use the built in .NET expression resolution stuff, to grab the StorageContainer.SourceImages value, stick it in the trigger attribute, and everything worked great.

Now, in .NET 8 isolated worker, I have to change my function parameters / trigger information a bit.

[Function("PhotoDataIndexer")]
public async Task Run([BlobTrigger(
    "mycontainer/{name}",
    Connection = "BlobFuncConnectionString")]
string stream, string name)

This works, it's picking up the blobs.

However, I do not want to have to supply the container name mycontainer directly in the function definition. I want to keep using my app setting reference of %StorageContainer:SourceImages% to grab the name.

Is this not possible in .NET 8 isolated worker model?


Solution

  • You can use the same method in Isolated-process model.

    This worked for me.

    using System;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.Logging;
    using Microsoft.Extensions.Options;
    
    namespace FunctionApp16
    {
        public class Function2
        {
            private readonly ILogger<Function2> _logger;
    
            public Function2(ILogger<Function2> logger)
            {
                _logger = logger;
            }
    
            [Function(nameof(Function2))]
            public void Run([BlobTrigger("%StorageContainer:SourceImages%", Connection = "AzureWebJobsStorage")] string message)
            {
                _logger.LogInformation($"C# Queue trigger function processed: {message}");
            }
        }
    }
    

    FunctionApp16.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
        <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.3.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.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>
    

    Program.cs:

    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    
    var host = new HostBuilder()
        .ConfigureFunctionsWebApplication()
        .ConfigureServices(services =>
        {
            services.AddApplicationInsightsTelemetryWorkerService();
            services.ConfigureFunctionsApplicationInsights();
        })
        .Build();
    
    host.Run();
    
    

    local.settings.json:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
            "StorageContainer:SourceImages": "test"
      }
    }
    

    OUTPUT: