Durable Azure function binding types not registered when using dependency injection

放肆的年华 提交于 2020-04-11 05:46:05

问题


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://docs.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


回答1:


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)



来源:https://stackoverflow.com/questions/60509972/durable-azure-function-binding-types-not-registered-when-using-dependency-inject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!