Skip to content

MessagePublishing falls back to the expression interpreter where dynamic code is unavailable - #1173

Merged
jeremydmiller merged 1 commit into
mainfrom
fix/1171-message-publishing-aot
Nov 10, 2026
Merged

jeremydmiller merged 1 commit into
mainfrom
fix/1171-message-publishing-aot

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Fixes #1171.

MessagePublishing.build<TDelegate> compiled its per-message-type delegate with FastExpressionCompiler.CompileFast() unconditionally. CompileFast emits IL through DynamicMethod, which a Native AOT image refuses with PlatformNotSupportedException, so every projection side effect published through ProjectionBatchBase.PublishMessageAsync failed natively and paused its shard. Fisher's copy of this class, which the #1045 lift replaced, used Expression.Compile() and ran natively (fisher#430); fisher#542 is where the regression surfaced in Fisher's AOT consumer smoke.

Change

  • The cache-miss path branches on RuntimeFeature.IsDynamicCodeSupported, the same pattern LambdaBuilder uses: CompileFast() on a JIT runtime, Compile(preferInterpretation: true) otherwise. A publish is not on a hot enough path for the interpreter to matter.
  • The [RequiresDynamicCode] / IL2026 / IL2060 annotations stay (the cache miss still closes a generic method over a runtime type); the IL2026 justification no longer names CompileFast.
  • Two internal entry points (InterpretedTenantPublisher, InterpretedMetadataPublisher) build the interpreted delegate on demand so EventTests can hold that branch to the same contract on a JIT runtime, where the feature switch cannot be flipped.

Tests

EventTests.MessagePublishingTests gains three facts over the interpreted branch: the tenant overload closes over the runtime type, the metadata overload keeps the metadata, and the shapes the compiled branch handles (a struct message, a non-public type, a closed generic) work interpreted too. 10/10 green on net10.0 locally.

Downstream

Once this ships as 3.0.1, Fisher takes the pin on fisher#549 (the 2.0.0-alpha.1 release prep), its AOT consumer smoke should go green, and fisher#542 closes.

🤖 Generated with Claude Code

…mic code is unavailable

Closes #1171. MessagePublishing.build compiled its per-message-type delegate with
FastExpressionCompiler.CompileFast unconditionally. CompileFast emits IL through DynamicMethod, which
a Native AOT image refuses with PlatformNotSupportedException, so every projection side effect
published through ProjectionBatchBase.PublishMessageAsync failed natively and paused its shard.
Fisher's copy of this class, which the #1045 lift replaced, used Expression.Compile() and
ran natively (fisher#430); fisher#542 is where the regression surfaced.

The cache-miss path now branches on RuntimeFeature.IsDynamicCodeSupported, as LambdaBuilder does:
CompileFast on a JIT runtime, Compile(preferInterpretation: true) otherwise. The interpreted branch
is reachable through two internal entry points so EventTests holds it to the same contract on a JIT
runtime, where the feature switch cannot be flipped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jeremydmiller

Copy link
Copy Markdown
Member Author

Evidence beyond the unit tests, from the Fisher side:

  • EventTests.MessagePublishingTests is 10/10 on net11.0 as well as net10.0, and JasperFx.AotSmoke still builds with its IL codes promoted to errors; JasperFx.Events reports no IL warning on MessagePublishing.
  • End to end against the case fisher#542 reports: this branch packed as 3.0.1-local.1, Fisher's smoke/aot-consumer pinned to it and run with dotnet run (dynamic code off, since the project sets PublishAot). On 3.0.0 it fails in UnmeasuredPaths.HostedDaemonAsync with the PlatformNotSupportedException above and then times out; on this branch it prints OK: documents and events written and read in a native image., with the published HarbourAnnounced message asserted. The published message was the smoke's only AOT failure: with just that one call removed, 3.0.0 passes every other path (raised event, subscription, hosted daemon, raw SQL, second store).

@jeremydmiller
jeremydmiller merged commit a1aa3f2 into main Nov 10, 2026
3 checks passed
jeremydmiller added a commit that referenced this pull request Nov 10, 2026
Patch release carrying #1173: MessagePublishing falls back to the expression interpreter where
dynamic code is unavailable, so projection side effects publish in a Native AOT image (#1171).

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
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.

MessagePublishing.CompileFast throws under Native AOT, so ProjectionBatchBase side effects fail

1 participant