Skip to content

Generator is creating invalid C# when used on an activity function with no input (object?) #730

Description

@leymbda

Using Microsoft.DurableTask.Generators 2.1.0-preview.1, I'm creating the following activity function:

[DurableTask]
public class WorkerCapacityReviewActivity(IWorkerPoolRepository repository) : TaskActivity<object?, WorkerCapacityReviewResult>
{
    public override async Task<WorkerCapacityReviewResult> RunAsync(TaskActivityContext context, object? input)
    {
        // some irrelevant work here
    }
}

Since this is just a check for the current capacity of the system this activity doesn't require an input, so I'm using object?. The problem comes when the generator runs on this:

[Function(nameof(WorkerCapacityReviewActivity))]
public static async Task<WorkerCapacityReviewResult> WorkerCapacityReviewActivity([ActivityTrigger] object? input = default, string instanceId, FunctionContext executionContext)
{
    ITaskActivity activity = ActivatorUtilities.GetServiceOrCreateInstance<WorkerCapacityReviewActivity>(executionContext.InstanceServices);
    TaskActivityContext context = new GeneratedActivityContext("WorkerCapacityReviewActivity", instanceId);
    object? result = await activity.RunAsync(context, input);
    return (WorkerCapacityReviewResult)result!;
}

As you can see, it is adding = default to the input, but this is not valid given there are subsequent arguments that dont also have default values. As a workaround I believe I need to make it pass through an unused value, which should work but is certainly not ideal.

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions