Skip to content

Exception.ToString is different with .NET 11 #128723

Description

@richlander

Program.cs:

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

Console.WriteLine(RuntimeInformation.FrameworkDescription);



await OuterAsync();

static async Task OuterAsync()
{
    await Task.CompletedTask;
    await MiddleAsync();
}

static async Task MiddleAsync()
{
    await Task.CompletedTask;
    await InnerAsync();
   throw new InvalidOperationException("boom");
}

static async Task InnerAsync()
{
    await Task.CompletedTask;
}

project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net11.0;net10.0</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <Features Condition="'$(TargetFramework)' == 'net11.0'">runtime-async=on</Features>
  </PropertyGroup>
</Project>

.NET 10 (everything default):

$ dotnet run -f net10.0
.NET 10.0.8
Unhandled exception. System.InvalidOperationException: boom
   at Program.<<Main>$>g__MiddleAsync|0_1() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 24
   at Program.<<Main>$>g__OuterAsync|0_0() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 15
   at Program.<Main>$(String[] args) in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 10
   at Program.<Main>(String[] args)

.NET 11 (async v2 off):

dotnet run -f net11.0
.NET 11.0.0-preview.4.26230.115
Unhandled exception. System.InvalidOperationException: boom
   at Program.<<Main>$>g__MiddleAsync|0_1() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 24
   at Program.<<Main>$>g__OuterAsync|0_0() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 15
   at Program.<Main>$(String[] args) in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 10
   at Program.<Main>(String[] args)
   at System.Environment.CallEntryPoint(IntPtr entryPoint, String[]* pArgument, Int32* pReturnValue, Boolean captureException, Exception* pException)

.NET 11 (async v2 on):

dotnet run -f net11.0
.NET 11.0.0-preview.4.26230.115
Unhandled exception. System.InvalidOperationException: boom
   at Program.<<Main>$>g__MiddleAsync|0_1() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 24
   at Program.<<Main>$>g__OuterAsync|0_0() in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 15
   at Program.<Main>$(String[] args) in /Users/rich/git/build-talk-2026/runtime-async-demo/Program.cs:line 10
--- End of stack trace from previous location ---
   at Program.<Main>(String[] args)
   at System.Environment.CallEntryPoint(IntPtr entryPoint, String[]* pArgument, Int32* pReturnValue, Boolean captureException, Exception* pException)

Both of the .NET 11 examples are different from the .NET 10 baseline.

Activity

  1. added
    untriaged
    on May 28, 2026
  2. richlander commented on May 28, 2026

    @richlander
    MemberAuthor

    As a side-note, I was surprised that all the methods are g__. That's due to top-level statements since a class needs to be materialized. That's not a concern but FYI for anyone wondering.

  3. jkotas commented on May 28, 2026

    @jkotas
    Member

    System.Environment.CallEntryPoint

    #127677

  4. rcj1 commented on May 29, 2026

    @rcj1
    Contributor

    We have filtered out these spurious markers in asyncv1 here:

    if (sf.IsLastFrameFromForeignExceptionStackTrace && !isAsync)

    The issue had been masked because if we resume before throwing, this marker just so happens to land on the DispatchContinuations stack trace hidden method, and we only print the marker if it lands on non-hidden code. I linked the PR to fix this.

  5. richlander commented on May 29, 2026

    @richlander
    MemberAuthor

    Thanks to both of you. These are good fixes to make this new feature look good.

  6. dotnet-policy-service commented on May 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  7. added a commit that references this issue on Jun 7, 2026
    08db7a3
  8. removed
    untriaged
    on Jun 7, 2026
  9. MichalStrehovsky commented on Jun 9, 2026

    @MichalStrehovsky
    Member

    This was reverted.

  10. rcj1 commented on Jun 9, 2026

    @rcj1
    Contributor

    I’ll have a quick look at the NAOT v1 stacktrace and if there is no regression with V2 I will just exclude the tests on NAOT

  11. added a commit that references this issue on Jun 9, 2026
  12. locked and limited conversation to collaborators on Jul 9, 2026
  13. added 2 commits that reference this issue on Jul 15, 2026
    b3b5f3a
    8e326f1
  14. added 2 commits that reference this issue on Jul 22, 2026
    301bf6c
    9a2f3b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions