Skip to content

Saga correlation id loading falls back to expression compilation instead of using the source-generated correlation accessor - #7922

Merged
danielmarbach merged 1 commit into
release-10.2from
backport-sourcegen-saga
Sep 3, 2026
Merged

Saga correlation id loading falls back to expression compilation instead of using the source-generated correlation accessor#7922
danielmarbach merged 1 commit into
release-10.2from
backport-sourcegen-saga

Conversation

@danielmarbach

@danielmarbach danielmarbach commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Backport of c55ef09 to release-10.2.

Symptoms

Saga correlation lookup compiles and invokes an expression tree at runtime on first use per saga type instead of using the source-generated accessor. The generated accessor is discarded before SagaMapper is built, and the generated code also has issues with the receiver type, duplicate property identities, and setter signatures.

Who's affected

Endpoints that map saga correlation to a saga-data property (mapper.MapSaga(...).ToMessage(...)) and build saga metadata from the source generator, which is the default for saga metadata. The generated path must also distinguish saga-data classes that share a correlation property name and type.

Root cause

SagaMetadata.Create accepts the generated accessor but does not pass it to SagaMapper, so every saga uses the expression-compiled fallback. The generator declares UnsafeAccessor members against IContainSagaData instead of the concrete saga-data type, deduplicates accessors by property name and type alone, and emits setters that return the property type instead of void.

Confirmed workarounds

No runtime workaround is needed. Correlation loading continues through the expression-compiled fallback, so sagas function as before.

Change

Generate accessors for the concrete saga-data type, key them by saga-data type and property identity, and emit void setters. Tests cover two saga-data classes with the same correlation property name and type.

@danielmarbach danielmarbach changed the title Key generated saga correlation accessors by saga-data type and exercise them at runtime Fix generated saga correlation accessors to target the concrete saga-data type Sep 2, 2026
@danielmarbach danielmarbach changed the title Fix generated saga correlation accessors to target the concrete saga-data type Generated saga correlation accessors are declared against IContainSagaData instead of the concrete saga-data type Sep 2, 2026
@danielmarbach danielmarbach changed the title Generated saga correlation accessors are declared against IContainSagaData instead of the concrete saga-data type Processing a saga message fails with System.MissingMethodException when the saga is registered via the source generator Sep 2, 2026
@danielmarbach danielmarbach changed the title Processing a saga message fails with System.MissingMethodException when the saga is registered via the source generator Saga correlation id loading falls back to expression compilation instead of using the source-generated correlation accessor Sep 2, 2026
@danielmarbach danielmarbach added this to the 10.2.9 milestone Sep 2, 2026
@danielmarbach

Copy link
Copy Markdown
Contributor Author

This one #7921 should also go into the patch I think

@danielmarbach
danielmarbach merged commit 84b196f into release-10.2 Sep 3, 2026
4 checks passed
@danielmarbach
danielmarbach deleted the backport-sourcegen-saga branch September 3, 2026 05:37
@danielmarbach

Copy link
Copy Markdown
Contributor Author

I realized my notes were incorrect, and I need to backport another commit. I will follow up shortly

@danielmarbach

Copy link
Copy Markdown
Contributor Author

Here it is #7924

danielmarbach added a commit that referenced this pull request Sep 3, 2026
…7924)

Partial backport of cd2db0b (#7918) to release-10.2, complementing the #7922 generator fix.

SagaMetadata.Create now forwards the generated correlation accessor to SagaMapper, so correlation ids load through the source-generated accessor instead of runtime expression compilation. The saga source generator parses and emits finder-only sagas with a null correlation accessor, and the AddSaga IL2026 suppressor only suppresses when an interceptor can actually be emitted.

The AddMessage<>-related changes of the original commit are intentionally not backported.

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants