Skip to content

feat: implement Dapr.StateManagement package — AOT-safe, reflection-free#1806

Draft
Copilot wants to merge 7 commits intomasterfrom
copilot/implement-dapr-statemangement
Draft

feat: implement Dapr.StateManagement package — AOT-safe, reflection-free#1806
Copilot wants to merge 7 commits intomasterfrom
copilot/implement-dapr-statemangement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Description

Ensures the Dapr.StateManagement implementation (and shared infrastructure in Dapr.Common) does not use reflection and is fully Native AOT-safe.

Changes Made

AOT / Reflection Elimination

  • IDaprSerializer — Added a new Serialize<T>(T value) generic overload. The non-generic Serialize(object?, Type?) and Deserialize(string?, Type) overloads (which accept a runtime Type) are now annotated with [RequiresUnreferencedCode] and [RequiresDynamicCode] to make their AOT-unsafety explicit.
  • JsonDaprSerializer — Implements the new Serialize<T>(T) overload using JsonSerializer.Serialize<T>(value, options), which is fully AOT-safe. Matching annotations added to the non-generic overloads.
  • DaprStateManagementGrpcClient.SerializeValue<TValue> — Changed from Serializer.Serialize(value, typeof(TValue)) (reflection path) to Serializer.Serialize<TValue>(value) (AOT-safe generic path).
  • DaprClientBuilderExtensions.AddDaprClient<> — Replaced two Activator.CreateInstance calls with explicit Func<IConfiguration?, TClientBuilder> and Func<IServiceCollection, TServiceBuilder> factory delegate parameters. No reflection is used in the hot path.

Callers Updated

All 6 AddDaprClient<> callers updated to pass explicit factory lambdas (config => new TClientBuilder(config) / svc => new TServiceBuilder(svc)): Jobs, Cryptography, AI, DistributedLock, Messaging, and StateManagement.

Test Fixes (Build Failure)

  • DaprClientBuilderExtensionsTests — Updated all 4 call sites to pass the two new required factory delegate parameters. Fixed DaprTestClientBuilder.Build() which was throwing NotImplementedException; it now correctly calls BuildDaprClientDependencies and returns a real DaprTestGrpcClient.
  • Dapr.Workflow.Test stub serializers — Added the missing Serialize<T>(T) method to 6 stub/mock IDaprSerializer/IWorkflowSerializer implementations: StubSerializer, CapturingSerializer, StubDaprSerializer, StubWorkflowSerializer, DependencyBasedSerializer, and MockSerializer.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

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 May 8, 2026 18:21
…<> alignment

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/393269e7-0b77-46e5-b002-ce1e9e547858

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
…ator csproj and FNV hash

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/393269e7-0b77-46e5-b002-ce1e9e547858

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
…, generic Serialize<T> overload

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/63945548-1b45-4e00-8494-4af62136db8b

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

❌ Patch coverage is 30.54893% with 291 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.86%. Comparing base (85f94fa) to head (991278c).

Files with missing lines Patch % Lines
...anagement.Runtime/DaprStateManagementGrpcClient.cs 10.96% 274 Missing and 2 partials ⚠️
...ateManagement.Abstractions/Models/BulkStateItem.cs 0.00% 6 Missing ⚠️
...tateManagement.Abstractions/StateStoreAttribute.cs 0.00% 6 Missing ⚠️
...rc/Dapr.Common/Serialization/JsonDaprSerializer.cs 0.00% 1 Missing ⚠️
...nagement.Abstractions/DaprStateManagementClient.cs 83.33% 1 Missing ⚠️
.../DaprStateManagementServiceCollectionExtensions.cs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1806      +/-   ##
==========================================
- Coverage   65.42%   63.86%   -1.57%     
==========================================
  Files         296      308      +12     
  Lines        8694     9093     +399     
  Branches     1009     1065      +56     
==========================================
+ Hits         5688     5807     +119     
- Misses       2761     3040     +279     
- Partials      245      246       +1     
Flag Coverage Δ
net10.0 63.85% <30.54%> (-1.57%) ⬇️

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.

@WhitWaldo
Copy link
Copy Markdown
Contributor

@copilot This project is failing to build. Can you give it another pass?

…use new AddDaprClient<> factory delegates

Agent-Logs-Url: https://github.com/dapr/dotnet-sdk/sessions/4e81dcdf-2201-490f-9729-b9ae4477ab19

Co-authored-by: WhitWaldo <2238529+WhitWaldo@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 9, 2026

@copilot This project is failing to build. Can you give it another pass?

Fixed in 9ab98d1. Two root causes:

  1. DaprClientBuilderExtensionsTests — The 4 test call sites still used the old AddDaprClient<> signature (no factory delegates). Updated all 4 to pass config => new DaprTestClientBuilder(config) and svc => new DaprTestBuilder(svc). Also fixed DaprTestClientBuilder.Build() which was throwing NotImplementedException — it now calls BuildDaprClientDependencies and returns a real DaprTestGrpcClient.

  2. Dapr.Workflow.Test stub serializers — Adding Serialize<T>(T) to IDaprSerializer broke 6 stub/mock implementations (StubSerializer, CapturingSerializer, StubDaprSerializer, StubWorkflowSerializer, DependencyBasedSerializer, MockSerializer). Added the missing method to each.

Full solution now builds cleanly; 74 Dapr.Common.Test + 367 Dapr.Workflow.Test pass.

Copilot AI changed the title feat: implement Dapr.StateManagement package feat: implement Dapr.StateManagement package — AOT-safe, reflection-free May 9, 2026
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