Skip to content

Fix strong-typed saga ID causing CS0246 code generation error#2481

Merged
jeremydmiller merged 2 commits intomainfrom
fix/2465-strong-id-saga-codegen
Apr 9, 2026
Merged

Fix strong-typed saga ID causing CS0246 code generation error#2481
jeremydmiller merged 2 commits intomainfrom
fix/2465-strong-id-saga-codegen

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Fixes #2465 — using a saga with a strong-typed ID type (e.g. a record struct wrapping Guid) caused CS0103/CS0246 compilation errors in the generated handler code.

  • Root cause: PullSagaIdFromEnvelopeFrame called NameInCode() (bare type name, e.g. MessageId) instead of FullNameInCode() (fully qualified, e.g. My.App.MessageId) when emitting TryParse calls for non-Guid saga ID types. When the generated code ran in a context that didn't import the saga ID's namespace the type couldn't be resolved.
  • Fix: One-line change in PullSagaIdFromEnvelopeFrame.GenerateCodeNameInCode()FullNameInCode(), consistent with how PullSagaIdFromMessageFrame.generateStrongTypedIdCode already handles this.

Changes

  • src/Wolverine/Persistence/Sagas/PullSagaIdFromEnvelopeFrame.cs — the fix
  • src/Testing/CoreTests/Bugs/Bug_2465_strong_typed_id_saga_codegen.cs — regression test with a record struct StrongSagaId(Guid) saga; covers host startup (code gen) and the envelope-path message routing
  • docs/guide/durability/sagas.md — new "Strong-Typed Identifiers" section documenting the TryParse requirement and usage pattern

Test plan

  • Bug_2465_strong_typed_id_saga_codegen.host_starts_successfully_with_strong_typed_saga_id — host startup with strong-typed saga ID succeeds (code gen OK)
  • Bug_2465_strong_typed_id_saga_codegen.can_start_saga_with_strong_typed_id — saga is created and persisted correctly
  • Bug_2465_strong_typed_id_saga_codegen.handle_message_via_envelope_saga_id_path — message with no saga ID field is routed via PullSagaIdFromEnvelopeFrame (the fixed code path)

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits April 9, 2026 15:50
Replace culture-sensitive ToLower() with ToLowerInvariant() in all SQL identifier
normalization paths. In Turkish locale, 'I'.ToLower() produces dotless 'ı' instead
of 'i', corrupting SQL names such as queue/table identifiers used in envelope storage.

Affects SqlServerTransport, PostgresqlTransport, MySqlTransport, SqliteTransport,
and SagaTableDefinition. Adds a regression test that verifies SanitizeIdentifier
behaves correctly under tr-TR culture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`PullSagaIdFromEnvelopeFrame` used `NameInCode()` (bare type name) when
emitting `TryParse` calls for non-Guid saga ID types. For strong-typed
identifiers in a custom namespace this produced unresolvable type references
(CS0103/CS0246) in the generated handler code.

Changed to `FullNameInCode()` so the fully qualified type name is always
emitted, matching the approach already used in `PullSagaIdFromMessageFrame`
for its strong-typed-ID path.

Added a regression test (`Bug_2465_strong_typed_id_saga_codegen`) that uses a
`record struct StrongSagaId(Guid)` with a `TryParse` method and verifies that
the host starts (code generation succeeds) and that messages routed through the
envelope path are handled correctly.

Also added a "Strong-Typed Identifiers" documentation section in sagas.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 4092ff7 into main Apr 9, 2026
17 of 19 checks passed
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.

Strong ID on saga type causes code generation error

1 participant