1

This is how I use async/Task in Console App:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CaseDurableFunctionConsole
{

    class Program
    {
        static async Task<List<string>> RunOrchestrator()
        {
            Console.WriteLine("Hello World!");
            Console.ReadLine();
            var outputs = new List<string>();
            return outputs;
        }

        static void Main(string[] args)
        {
            RunOrchestrator();
        }
    }
}

This works well and this is the output:

enter image description here

(Even without using await, it shows the right result.)

But when I use async/Task in Azure Functions, like this:

[FunctionName("Function1")]
public static async Task<List<string>> RunOrchestrator(
    [OrchestrationClient] DurableOrchestrationClient orchestrationClient)
{
    var outputs = new List<string>();
    await Task.Delay(1);
    return outputs;
}

Then it comes up with an error after started.

[2019/11/25 5:50:50] Error indexing method 'Function1' [2019/11/25 5:50:50] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Functions must return Task or void, have a binding attribute for the return value, or be triggered by a binding that natively supports return values.

[2019/11/25 5:50:56] The 'Function1' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Functions must return Task or void, have a binding attribute for the return value, or be triggered by a binding that natively supports return values.

How can I fix this by modify my Function Code?

3 Answers 3

1

This has nothing to do with async-await.

The log message states that, for that binding, the method should return Task or void and your method returns Task<List<string>>.

Your function method does not equate to the RunOrchestrator method in your console application. It equates to the Main method.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for reply. I feel that you should be right, but how can I return Task? I am a little dizzy about that.
Have you tried just making the method signature public static async Task RunOrchestrator([OrchestrationClient] DurableOrchestrationClient orchestrationClient)?
0

Checked the documentation, here is the reason:

Orchestrations can schedule durable timers to implement delays or to set up timeout handling on async actions. Use durable timers in orchestrator functions instead of Thread.Sleep and Task.Delay (C#) or setTimeout() and setInterval() (JavaScript).

For more information and for examples, see the Durable timers article.

2 Comments

Hi, Jack. Do you have any suggestions of how to modify my code? Actually, I don't know how to modify the code to avoid this problem.
Check the sample: Orchestrator.cs
0

Due to replay constraints of orchestrators, you mustn't await anything other than the orchestration context, or use sleep methods.

To wait, in a durable "replay" safe way, try:

await orchestrator.CreateTimer(orchestrator.CurrentUtcDateTime.AddMinutes(15), CancellationToken.None);

Also, you don't appear to have implemented an orchestration trigger function correctly. You need a trigger parameter such as:

[OrchestrationTrigger] IDurableOrchestrationContext orchestrator

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.