Repository navigation
[Mocha] Fix the dispatch context never assigning its runtime - #10693
Merged
PascalSenn merged 2 commits intoOct 27, 2026
Merged
Conversation
DispatchContext.Initialize received the messaging runtime but only used it for the host and the default content type, so IDispatchContext.Runtime was null in every dispatch middleware. Assign it the way ReceiveContext does and cover publish, send and request with a test.
tobias-tengler
approved these changes
Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Mocha,
IDispatchContext.Runtimeis null while a dispatch middleware runs. Any middleware that reads it, for example to look up the outbound routes of the dispatched type throughcontext.Runtime.Router, throws aNullReferenceException.DispatchContext.Initializereceives the messaging runtime and uses it forHostand the default content type, but never assigns theRuntimeproperty.Resetclears the property when the context returns to the pool, andReceiveContext.Initializeassigns it, so the dispatch side was the only one missing the assignment. Every dispatch path goes through this method: publish, send, request, scheduled dispatch, and the fault, dead-letter, redelivery and outbox dispatchers.This change assigns
RuntimeinDispatchContext.Initialize, in the same position as inReceiveContext.Initialize.The new test,
Initialize_Should_AssignRuntime_When_MessageIsPublishedSentOrRequested, capturescontext.Runtimefrom a dispatch middleware for a publish, a send and a request, and checks that every captured value is the registered runtime instance. Before the fix all three cases failed with a null runtime. The request case also covers the reply dispatch.