Skip to content

Cannot box a ByRef-like (ref struct) when using a CreateDelegate method on method that accepts a ByRef-like parameter. #72548

Closed

Description

@Qapples

The following code correctly runs on CoreCLR and fails on NativeAOT:
https://gist.github.com/Suchiman/b09ad481065e3e2b17d89e321121bacc

NativeAOT fails with the following exception: System.NotSupportedException: Cannot create boxed ByRef-like values.

The issue occurs at this line:
typeof(Program).GetMethod("Method")!.CreateDelegate<ExampleDelegate>();

Activity

  1. changed the title [-]Cannot box a ByRef-like (ref struct) when using a CreateDelegate method on method that accepts a ByRef-like parmater.[/-] [+]Cannot box a ByRef-like (ref struct) when using a CreateDelegate method on method that accepts a ByRef-like parameter.[/+] on Jul 13, 2021
  2. MichalStrehovsky commented on Jul 13, 2021

    @MichalStrehovsky
    Member

    Related to dotnet/runtimelab#265. We block reflection invoke on everything byref-like. Unfortunately it includes reflection-creating a delegate, which is not a fundamental problem. We probably need to generate entries for this in the AOT compiler and filter them out elsewhere.

  3. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jul 20, 2022
  4. self-assigned this
    on Jul 26, 2022
  5. added a commit that references this issue on Jul 27, 2022
  6. added this to the 7.0.0 milestone on Jul 29, 2022
  7. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 31, 2022
  8. added a commit that references this issue on Jul 31, 2022
    b08f4ee
  9. added a commit that references this issue on Aug 2, 2022
    f348338
  10. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 2, 2022
  11. ghost locked as resolved and limited conversation to collaborators on Sep 1, 2022
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions