Skip to content

Analyzer DURABLE2001 fails for activities that require FunctionContext without input data #3172

@jholtmann

Description

@jholtmann

Description

When calling an activity that has no input DTO but still requires FunctionContext from an orchestrator, the DURABLE2001 analyzer reports an incorrect warning with the text: CallActivityAsync is passing the incorrect type 'none' instead of 'FunctionContext' to the activity function 'DemoActivity'.

DemoFunctionApp succeeded with 1 warning(s) (2.0s) → DemoFunctionApp\bin\Release\net8.0\DemoFunctionApp.dll
    C:\Users\jholtmann\source\repos\DemoFunctionApp\DemoFunctionApp\Demo.cs(16,19): warning DURABLE2001: CallActivityAsync is passing the incorrect type 'none' instead of 'FunctionContext' to the activity function 'DemoActivity'

Expected behavior

  • The analyzer should not report a warning in this scenario.

Actual behavior

  • The analyzer reports a spurious warning.

Relevant source code snippets

    public class Demo
    {
        [Function(nameof(DemoOrchestrato))]
        public async Task DemoOrchestrato([OrchestrationTrigger] TaskOrchestrationContext context)
        {
            await context.CallActivityAsync(nameof(DemoActivity));
        }

        [Function(nameof(DemoActivity))]
        public async Task DemoActivity([ActivityTrigger] FunctionContext context)
        {
            context.GetLogger<Demo>().LogInformation("Hello from DemoActivity");
            await Task.Delay(1);
        }

        [Function(nameof(DemoTrigger))]
        public async Task<HttpResponseData> DemoTrigger(
            [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
            [DurableClient] DurableTaskClient starter,
            FunctionContext context
        )
        {
            context.GetLogger<Demo>().LogInformation("C# HTTP trigger function processed a request.");

            var instanceId = await starter.ScheduleNewOrchestrationInstanceAsync(nameof(DemoOrchestrato));
            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    }

Known workarounds

  • Disabling the analyzer DURABLE2001 at the project level resolves the warning

App Details

  • Microsoft.Azure.Functions.Worker.Extensions.DurableTask: 1.6.0+
  • Azure Functions runtime: 2.0
  • Language: C#

Screenshots

Image Image

If deployed to Azure

  • No Azure deployment required, reproduces in IDE/when compiling with dotnet build -c Release

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority 2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions