Skip to content

Workflow versioning source generator fails with compile errors for generic workflow base classes #1859

Description

@mtaghavi2005

Expected Behavior

The Dapr workflow versioning source generator should ignore abstract or open generic workflow base classes, or otherwise avoid emitting registration/versioning entries for them.

For a concrete workflow that inherits through a generic workflow base class, the generator should only register the concrete closed workflow type:

internal abstract class VersionedWorkflow<TInput, TOutput> : Workflow<TInput, TOutput>
{
}

internal sealed partial class OrderProcessingWorkflow
    : VersionedWorkflow<OrderPayload, OrderResult>
{
    public override Task<OrderResult> RunAsync(WorkflowContext context, OrderPayload order)
    {
        // workflow implementation
    }
}

The generated code should compile and should not emit references to the open generic base type.

Actual Behavior

The workflow versioning source generator discovers the abstract open generic base class as a workflow and emits it into the generated registry.

This produces invalid generated code containing unresolved generic type parameters:

options.RegisterWorkflow<global::DaprWorkflowExploration.ApiService.Workflows.VersionedWorkflow<TInput, TOutput>>(...);

new Entry(
    typeof(global::DaprWorkflowExploration.ApiService.Workflows.VersionedWorkflow<TInput, TOutput>),
    ...);

The build then fails with CS0246 because TInput and TOutput are not in scope in the generated registry file.

Representative errors:

Dapr_Workflow_Versioning.g.cs(24,263): error CS0246: The type or namespace name 'TInput' could not be found
Dapr_Workflow_Versioning.g.cs(24,271): error CS0246: The type or namespace name 'TOutput' could not be found
Dapr_Workflow_Versioning.g.cs(87,109): error CS0246: The type or namespace name 'TInput' could not be found
Dapr_Workflow_Versioning.g.cs(87,117): error CS0246: The type or namespace name 'TOutput' could not be found

Steps to Reproduce the Problem

  1. Add a workflow that derives directly from Workflow<TInput, TOutput> and confirm it builds:
internal sealed partial class OrderProcessingWorkflow : Workflow<OrderPayload, OrderResult>
{
    public override Task<OrderResult> RunAsync(WorkflowContext context, OrderPayload order)
    {
        return Task.FromResult(new OrderResult());
    }
}
  1. Change only the inheritance to use an abstract generic base class:
internal abstract class VersionedWorkflow<TInput, TOutput> : Workflow<TInput, TOutput>
{
}

internal sealed partial class OrderProcessingWorkflow
    : VersionedWorkflow<OrderPayload, OrderResult>
{
    public override Task<OrderResult> RunAsync(WorkflowContext context, OrderPayload order)
    {
        return Task.FromResult(new OrderResult());
    }
}
  1. Build the project.

The build fails in the generated file:

Dapr.Workflow.Versioning.Generators/Dapr.Workflow.Versioning.WorkflowSourceGenerator/Dapr_Workflow_Versioning.g.cs

The likely root cause is that BuildDiscoveredWorkflow marks abstract and open generic workflow types with IsAbstractOrGeneric, and the simple auto-registration path uses that flag to exclude them. The versioning registration path does not apply the same filter, so it still generates registration and registry entries for every discovered workflow, including abstract/open generic base classes.

Release Note

RELEASE NOTE: FIX Workflow versioning source generator ignores abstract/open generic workflow base classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions