Mark custom continuation resumptions as StackTraceHidden#130777
Merged
jakobbotsch merged 2 commits intoJul 16, 2026
Conversation
E.g.
```csharp
public static async Task Main()
{
Task t = ThrowsSoon();
try
{
await t;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private static async Task ThrowsSoon()
{
await Task.Delay(50);
throw new Exception("Exception thrown");
}
```
```diff
System.Exception: Exception thrown
at Program.ThrowsSoon() in C:\dev\dotnet\playground\Program.cs:line 24
- at System.Runtime.CompilerServices.RuntimeAsyncTaskContinuation.TaskContinuationResume.ResumeTaskContinuation(Continuation cont, Byte& result)
at Program.Main() in C:\dev\dotnet\playground\Program.cs:line 13
```
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hides internal async continuation resumption frames from user-visible exception stack traces by marking the relevant resumption helpers as [StackTraceHidden], and adds tests to ensure those frames no longer appear for both Task and ValueTask/IValueTaskSource continuation paths.
Changes:
- Mark
RuntimeAsyncTaskContinuation.TaskContinuationResume.ResumeTaskContinuationas[StackTraceHidden]. - Mark
AsyncHelpers.ValueTaskSourceContinuation.ValueTaskSourceContinuationResume.ResumeValueTaskSourceContinuationas[StackTraceHidden]. - Extend
StackTraceTestswith new async scenarios and assertions that"ResumeTaskContinuation"/"ResumeValueTaskSourceContinuation"are absent fromException.ToString()output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Diagnostics.StackTrace/tests/StackTraceTests.cs | Adds new async test cases (Task + custom IValueTaskSource) and asserts resumption helpers don’t appear in exception text. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeAsyncTaskContinuation.cs | Adds [StackTraceHidden] to the Task continuation resume helper to suppress it from stack traces. |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.ValueTaskSourceContinuation.cs | Adds [StackTraceHidden] to the ValueTaskSource continuation resume helper to suppress it from stack traces. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Member
Author
|
PTAL @rcj1 |
This was referenced Jul 15, 2026
Open
rcj1
approved these changes
Jul 15, 2026
Member
Author
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
BrzVlad
added a commit
that referenced
this pull request
Jul 22, 2026
Test added in #130777. For code like the one below, where the `GetResult` of the value task source throws, the correct stacktrace should point to the await as the source of the throw. However, on interpreter, it is pointing to the new instruction. ``` public static async Task ThrowsSoonValueTaskSource() { ValueTask vt = new ValueTask(new ThrowsSoonValueTaskSourceImpl(), 0); await vt; } ``` The cause of this seems to be that we only report IL->native offsets for locations where the IL stack is empty, therefore we don't have a location at the await. This seems to be easily fixable via BrzVlad@460eae9. The problem with the fix is that it is a partial revert of #127469 so it has a good chance to lead to regressions on other diagnostic tests.
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.
E.g.
System.Exception: Exception thrown at Program.ThrowsSoon() in C:\dev\dotnet\playground\Program.cs:line 24 - at System.Runtime.CompilerServices.RuntimeAsyncTaskContinuation.TaskContinuationResume.ResumeTaskContinuation(Continuation cont, Byte& result) at Program.Main() in C:\dev\dotnet\playground\Program.cs:line 13