Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Durable Azure function binding types not registered when using dependency injection

I created a standard durable function based from visual studio "Add new function" to project. This works fine out of the box.

Then I followed the steps here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection to add dependency injection. Adding Microsoft.Extensions.http.

This breaks the function and I get error:

[03-Mar-20 14:58:18] The 'test' function is in error: The binding type(s) 'orchestrationTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
[03-Mar-20 14:58:18] The 'test_Hello' function is in error: The binding type(s) 'activityTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
[03-Mar-20 14:58:18] The 'test_HttpStart' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'test_HttpStart'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'starter' to type IDurableOrchestrationClient. 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.).

In this state startup.cs does not run, which has never happened before in previous functions I have created, but I can fix this by adding extensions.json with the following content:

{
  "extensions": [
    {
      "name": "Startup",
      "typeName": "FunctionApp1.Startup, FunctionApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    }
  ]
}

This makes Configure method in startup.cs run, but I still get the same errors.

startup.cs

public override void Configure(IFunctionsHostBuilder builder)
{
    builder.Services.AddHttpClient();
}

Function2.cs

public class Function2 { [FunctionName("test")] public async Task> RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) { var outputs = new List();

        // Replace "hello" with the name of your Durable Activity Function.
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "London"));

        // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
        return outputs;
    }

    [FunctionName("test_Hello")]
    public string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation($"Saying hello to {name}.");
        return $"Hello {name}!";
    }

    [FunctionName("test_HttpStart")]
    public async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
        [DurableClient]IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("test", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

I am using .net core 3.1 Microsoft.Azure.Functions.Extensions 1.0.0

Microsoft.Azure.WebJobs.Extensions.DurableTask 2.1.1

Microsoft.Extensions.Http 3.1.2

Microsoft.NET.sdk.Functions 3.0.4

like image 379
ruffen Avatar asked Jul 21 '26 04:07

ruffen


1 Answers

Just for now, try downgrading the Microsoft.NET.sdk.Functions 3.0.4 to a previuos version. The team made some performance improvements, but I've seen people raising the same issue (DI problems)

like image 188
Thiago Custodio Avatar answered Jul 22 '26 20:07

Thiago Custodio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!