Skip to content

Unskip NestedCatch_DuplicateLocal_Level2 #132016

Description

@JoeRobich

In the move from running against .NET 10 to .NET 11 preview, the following async runtime test failure was encountered:

CodeGenAsyncEHTests.NestedCatch_DuplicateLocal_Level2

System.NullReferenceException : Object reference not set to an instance of an object.



Stack trace
   at C.M2(String caller, Exception ex) in :line 64
   at C.M1(Boolean catchFirst1, Boolean catchFirst2) in :line 44
   at C.Main() in :line 14
   at C.<Main>()
   at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Activity

  1. added theissue type on Aug 7, 2026
  2. 333fred commented on Aug 7, 2026

    @333fred
    Member

    his appears to be a runtime-async bug in .NET 11 Preview 6. I reduced the test to the following file-based app:

    #:property Features=runtime-async=on
    #:property LangVersion=preview
    #:property Optimize=true
    #:property NoWarn=SYSLIB5007;CA2252
    
    using System;
    using System.Threading.Tasks;
    
    Test.Run();
    
    class Test
    {
        public static void Run()
        {
            new Test().M().GetAwaiter().GetResult();
        }
    
        static bool Filter(Exception ex, bool result)
        {
            Console.WriteLine(ex.Message);
            return result;
        }
    
        async Task M()
        {
            try
            {
                throw new Exception("outer");
            }
            catch (Exception ex) when (Filter(ex, false))
            {
                await Print(ex);
            }
            catch (Exception ex) when (Filter(ex, true))
            {
                try
                {
                    throw new Exception("inner");
                }
                catch (Exception ex2) when (Filter(ex2, false))
                {
                    await Print(ex);
                    await Print(ex2);
                }
                catch (Exception ex2) when (Filter(ex2, true))
                {
                    try
                    {
                        throw new Exception();
                    }
                    catch
                    {
                        await Print(ex);
                        await Print(ex2);
                    }
                }
            }
        }
    
        static async Task Print(Exception ex)
        {
            await Task.Yield();
            Console.WriteLine(ex.Message);
        }
    }

    With global.json pinned to SDK 10.0.301, this exits successfully:

    $ DOTNET_RuntimeAsync=1 dotnet run 84791.cs
    outer
    outer
    inner
    inner
    outer
    inner

    With global.json pinned to SDK 11.0.100-preview.6.26359.118, the same command fails because the second captured exception becomes null:

    $ dotnet run 84791.cs
    outer
    outer
    inner
    inner
    outer
    Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
       at Test.Print(Exception ex) in 84791.cs:line 63
       at Test.M() in 84791.cs:line 54

    This comment was generated by AI.

  3. transferred this issue fromdotnet/roslynon Aug 7, 2026
  4. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Aug 7, 2026
  5. dotnet-policy-service commented on Aug 7, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  6. added this to the 11.0.0 milestone on Aug 7, 2026
  7. removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 7, 2026
  8. locked and limited conversation to collaborators on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions