Ensure the handler invocation infrastructure does not pollute the stack trace#7582
Merged
danielmarbach merged 1 commit intomasterfrom Jan 8, 2026
Merged
Ensure the handler invocation infrastructure does not pollute the stack trace#7582danielmarbach merged 1 commit intomasterfrom
danielmarbach merged 1 commit intomasterfrom
Conversation
Contributor
Author
|
Wondering if this would be a great improvement to apply to internal behaviors too because it could significantly reduce the stack trace size |
andreasohlund
approved these changes
Jan 8, 2026
Member
👍 |
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.
I realized .NET has had for a while the StackTraceHiddenAttribute which makes in the majority of the cases things disappear from the stack trace and the stack trace when it is turned into a string. Since we replaced the exception tree part with a bit of class infrastructure, we are essentially adding more "weight" to the stack trace which has implications on transports that have limited message sizes because it might make it more likely to go over the message size limits.
This pull request improves the clarity of stack traces for error messages in NServiceBus by ensuring internal framework classes are hidden from stack traces, making it easier for users to diagnose issues. The changes include new attributes on key handler invoker and factory methods, and an acceptance test to verify the improvement.
Stack trace cleanliness improvements:
[DebuggerNonUserCode],[DebuggerStepThrough], and[StackTraceHidden]attributes to theInvokemethod inMessageHandlerInvokerto hide it from stack traces.TimeoutHandlerFactoryandMessageHandlerFactoryto use dedicated static methods (InvokeTimeoutandInvokeHandler) with the same stack trace hiding attributes, ensuring these methods do not appear in stack traces. [1] [2]Test coverage:
When_message_is_moved_to_error_queue.csto verify that stack traces for moved error messages do not contain internal NServiceBus classes likeMessageHandlerInvokerandMessageHandlerFactory.Documentation and maintainability:
MessageHandlerInvoker,TimeoutHandlerFactory, andMessageHandlerFactorysince they are referenced in acceptance tests for stack trace verification. [1] [2] [3] [4]Before:
after: