[NET] Use SetCurrentStackTrace for not thrown exceptions#117802
Merged
ManickaP merged 1 commit intodotnet:mainfrom Jul 18, 2025
Merged
[NET] Use SetCurrentStackTrace for not thrown exceptions#117802ManickaP merged 1 commit intodotnet:mainfrom
ManickaP merged 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances stack trace information for not-thrown exceptions in networking libraries by using ExceptionDispatchInfo.SetCurrentStackTrace(). This helps improve debugging by providing better stack traces when exceptions are created but wrapped in Task.FromException or ValueTask.FromException rather than being directly thrown.
- Applies
ExceptionDispatchInfo.SetCurrentStackTrace()to exceptions used withValueTask.FromExceptionandTask.FromException - Adds necessary
using System.Runtime.ExceptionServices;statements where needed - Updates exception creation patterns to preserve stack trace information for better debugging
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| WebSocketStream.cs | Wraps NotSupportedException and ObjectDisposedException instances with SetCurrentStackTrace |
| ManagedWebSocket.cs | Applies SetCurrentStackTrace to WebSocketException and OperationCanceledException |
| Socket.Tasks.cs | Wraps NotSupportedException with SetCurrentStackTrace |
| SocketsHttpHandler.cs | Applies SetCurrentStackTrace to various HTTP-related exceptions |
| Http3RequestStream.cs | Wraps ObjectDisposedException instances with SetCurrentStackTrace |
| Http2Stream.cs | Applies SetCurrentStackTrace to NotSupportedException, HttpRequestException, and ObjectDisposedException |
| Http2Connection.cs | Wraps ObjectDisposedException and IOException with SetCurrentStackTrace |
| ContentLengthWriteStream.cs | Applies SetCurrentStackTrace to HttpRequestException instances |
| HttpContent.cs | Wraps HttpRequestException instances with SetCurrentStackTrace |
Contributor
|
Tagging subscribers to this area: @dotnet/ncl |
ManickaP
commented
Jul 18, 2025
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
This was referenced Jul 18, 2025
MihaZupan
approved these changes
Jul 18, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #117652