Skip to content

JIT assert with UnsafeAccessor and delegate ctor #125866

Closed

Description

@MichalPetryka

Description

Using UnsafeAccessor to make a delegate from a pointer to a static virtual ends up with a JIT assert.

Reproduction Steps

using System;
using System.Runtime.CompilerServices;

internal unsafe class Program : IInterface
{
    public delegate object Del();

    [UnsafeAccessor(UnsafeAccessorKind.Constructor)]
    extern static Del Construct(object o, IntPtr p);

    public static void Main()
    {
        Construct(null, (nint)Resolver<Program>.Resolve())();
    }

    public static class Resolver<T> where T : IInterface
    {
        public static delegate*<object> Resolve() => &T.A;
    }
}

public interface IInterface
{
    public static virtual object A() => null;
}

Expected behavior

Works

Actual behavior

Assert failure(PID 47564 [0x0000b9cc], Thread: 42584 [0xa658]): Assertion failed 'targetMethodHnd == nullptr' in 'Program:Main():System.Void' during 'Morph - Inlining' (IL size 17; hash 0xb6bd7cc8; FullOpts)

    File: H:\Projects\dotnet\runtime\src\coreclr\jit\flowgraph.cpp:1109
    Image: H:\Projects\dotnet\runtime\artifacts\bin\coreclr\windows.x64.Checked\CoreRun.exe

Regression?

No idea

Known Workarounds

No response

Configuration

Main Windows x64

Other information

No response

Activity

  1. added
    untriaged
    on Mar 20, 2026
  2. added
    area-CodeGen-coreclr
    on Mar 20, 2026
  3. dotnet-policy-service commented on Mar 20, 2026

    @dotnet-policy-service
    Contributor

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

  4. removed
    untriaged
    on Mar 26, 2026
  5. added this to the 11.0.0 milestone on Mar 26, 2026
  6. added a commit that references this issue on Mar 30, 2026
    1da6c2e
  7. locked and limited conversation to collaborators on Apr 30, 2026
  8. added a commit that references this issue on Jul 15, 2026
    741c58f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions