Skip to content

Analyzer Rule DURABLE2001 False Positives #453

@wsugarman

Description

@wsugarman

The latest changes to the analyzers with 1.12.0 have introduced some false positives with rule DURABLE2001 including:

  • Flagging missing input on activities that bind to FunctionContext for their ActivityTrigger when used in Azure Functions:
[Function(nameof(GetNumber))]
public async Task<int> GetNumber([ActivityTrigger] FunctionContext context)
{
    // Something ...
}

[Function(nameof(DoMath))]
public async Task DoMath([OrchestrationTrigger] TaskOrchestrationContext context)
{
    // error DURABLE2001: CallActivityAsync is passing the incorrect type 'none' instead of 'FunctionContext' to the activity function 'GetNumber'
    int num = await context.CallActivityAsync<int>(nameof(GetNumber));
    // ... More stuff ...
}
  • Polymorphism does not seem to be considered properly on input. E.g. a List<int> argument is flagged as invalid when passed to an activity that accepts IReadOnlyList<int>. I know this can be a bit hairy given the extension's own JSON representation though.
    • Or perhaps all types represented by the same JSON type are acceptable alternatives? E.g. Any .NET BCL collection is a JSON array, so they can be interchanged? Although, that may rely too much on implementation details
[Function(nameof(Sum))]
public int Sum([ActivityTrigger] IReadOnlyList<int> numbers)
    => numbers.Sum();

[Function(nameof(DoMath))]
public async Task DoMath([OrchestrationTrigger] TaskOrchestrationContext context)
{
    // error DURABLE2001: CallActivityAsync is passing the incorrect type 'List<int>' instead of 'IReadOnlyList<int>' to the activity function 'Sum'
    List<int> numbers = [1, 2, 3, 4, 5];
    int sum = await context.CallActivityAsync<int>(nameof(Sum), numbers);
    // ... More stuff ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions