Skip to content

Skip DAPR1301 analyzer when AddDaprWorkflowVersioning is present#1778

Merged
WhitWaldo merged 6 commits intomasterfrom
copilot/fix-analyzer-dapr1301-warning
Apr 14, 2026
Merged

Skip DAPR1301 analyzer when AddDaprWorkflowVersioning is present#1778
WhitWaldo merged 6 commits intomasterfrom
copilot/fix-analyzer-dapr1301-warning

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

With Dapr 1.17 workflow versioning (Dapr.Workflow.Versioning), workflows are auto-registered by a source generator — manual RegisterWorkflow<T>() calls are not required. The DAPR1301 analyzer was unaware of this, producing spurious warnings (and AD0001 crashes) in projects using AddDaprWorkflowVersioning().

Description

  • Analyzer (WorkflowRegistrationAnalyzer): uses the deferred-diagnostics pattern to suppress DAPR1301 when AddDaprWorkflowVersioning from the Dapr versioning package is detected.

    • RegisterCompilationStartAction checks once per compilation whether WorkflowVersioningServiceCollectionExtensions is present in the referenced assemblies via GetTypeByMetadataName, preventing a user-defined method with the same name from accidentally suppressing the diagnostic.
    • When the versioning type is present, two RegisterSyntaxNodeAction handlers are registered: one semantically verifies that AddDaprWorkflowVersioning resolves to WorkflowVersioningServiceCollectionExtensions.AddDaprWorkflowVersioning (the actual Dapr method), and one collects potential DAPR1301 diagnostics — keeping explicit RegisterWorkflow<T> checks active per workflow call.
    • RegisterCompilationEndAction suppresses the collected diagnostics only if the Dapr versioning call was confirmed; otherwise they are reported as normal.
    • Fixed a pre-existing cross-tree crash in CheckIfWorkflowIsRegistered: same-tree invocations use semantic symbol comparison; invocations in other files fall back to syntactic name comparison (avoids RS1030).
  • Tests (Dapr.Workflow.Analyzers.Test):

    • Added VerifyWorkflowNotRegisteredButVersioningPresent — verifies no DAPR1301 is emitted when services.AddDaprWorkflowVersioning() is present and no manual RegisterWorkflow<T>() exists.
    • Added VerifyWorkflowRegisteredWithVersioningPresent — verifies no DAPR1301 is emitted when both AddDaprWorkflowVersioning and an explicit RegisterWorkflow<T> are present.
    • Project references follow the same pattern as Dapr.IntegrationTest.Workflow.Versioning (Dapr.Workflow.Versioning.Abstractions + Dapr.Workflow.Versioning.Runtime).

Issue reference

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Copilot AI and others added 2 commits April 12, 2026 23:08
… versioning references

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/ea469658-b9f0-4c16-9227-6fdb2a6b3f4b

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
…1301 versioning check

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/ea469658-b9f0-4c16-9227-6fdb2a6b3f4b

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
WhitWaldo added a commit to WhitWaldo/dapr-docs that referenced this pull request Apr 12, 2026
…l not apply when Dapr.Workflow.Versioning is installed.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.18%. Comparing base (7258f40) to head (e62aaa3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1778   +/-   ##
=======================================
  Coverage   61.18%   61.18%           
=======================================
  Files         285      285           
  Lines        8405     8405           
  Branches      974      974           
=======================================
  Hits         5143     5143           
  Misses       3026     3026           
  Partials      236      236           
Flag Coverage Δ
net10.0 61.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@WhitWaldo WhitWaldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few changes I'd like to see addressed

foreach (var invocation in root.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
if (invocation.Expression is MemberAccessExpressionSyntax memberAccess &&
memberAccess.Name.Identifier.Text == "AddDaprWorkflowVersioning")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While a minor point, I would like for this to look for the AddDaprWorkflowVersioning method from the Dapr.Workflow.Versioning assembly, not just any at all (though we're unlikely to have such a conflict).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a80f353. The check now uses the deferred-diagnostics pattern to get a proper semantic model: when the versioning type is present in the compilation, a RegisterSyntaxNodeAction handler fires on every InvocationExpression and calls semanticModel.GetSymbolInfo(invocation) to verify the resolved method's ContainingType equals WorkflowVersioningServiceCollectionExtensions. Only if that exact Dapr method is confirmed does the RegisterCompilationEndAction suppress the collected diagnostics.

context.RegisterSyntaxNodeAction(AnalyzeWorkflowRegistration, SyntaxKind.InvocationExpression);
context.RegisterCompilationStartAction(compilationContext =>
{
if (CheckIfWorkflowVersioningIsRegistered(compilationContext.Compilation))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While workflow versioning will automatically pick up all the workflows, I would also like for the analyzer to still run in case the user happens to define their own Workflow DI registrations, so can you ensure this scenario is covered as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a80f353. The deferred-diagnostics pattern keeps the per-workflow CheckIfWorkflowIsRegistered logic fully active even when versioning is present. For every ScheduleNewWorkflowAsync(nameof(X)) call, a node action checks explicit RegisterWorkflow<X> registrations first — if found, no diagnostic is added. If not found, a pending diagnostic is collected and later suppressed only because AddDaprWorkflowVersioning was confirmed. I also added a test VerifyWorkflowRegisteredWithVersioningPresent covering the combination of versioning + explicit registration.

…ks active; fix cross-tree semantic model crash

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/6e1d6688-99e4-4438-aed2-56f6e529ecf3

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
@WhitWaldo WhitWaldo marked this pull request as ready for review April 14, 2026 16:42
@WhitWaldo WhitWaldo requested review from a team as code owners April 14, 2026 16:42
@WhitWaldo WhitWaldo merged commit b3eaad0 into master Apr 14, 2026
369 of 374 checks passed
@WhitWaldo WhitWaldo deleted the copilot/fix-analyzer-dapr1301-warning branch April 14, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants