Skip to content

[browser][coreCLR] - Reflection.Pointer unboxing is broken #122343

@pavelsavara

Description

@pavelsavara
using System.Reflection;

public static unsafe void Main()
{
    JSMarshalerArgumentImpl arg;
    arg.Int32Value = 42;
    TestCpy1(&arg);

    var boxedLegacyArgs = Pointer.Box((void*)&arg, typeof(JSMarshalerArgumentImpl*));
    Console.WriteLine("Boxed " + (IntPtr)Pointer.Unbox(boxedLegacyArgs));

    var mi = typeof(Test).GetMethod("TestCpy1", BindingFlags.Public | BindingFlags.Static);
    
    mi.Invoke(null, new object[] { boxedLegacyArgs });
}

public static unsafe void TestCpy1(JSMarshalerArgumentImpl* arg)
{
    Console.WriteLine("TestCpy1 ptr " + (IntPtr)arg);
    Console.WriteLine("TestCpy1 " + arg->Int32Value);
}

public struct JSMarshalerArgumentImpl
{
    public int Int32Value;
}

Actual

TestCpy1 ptr 89980976
TestCpy1 42
Boxed 89980976
TestCpy1 ptr 48
TestCpy1 0

Expected

TestCpy1 ptr 89980976
TestCpy1 42
Boxed 89980976
TestCpy1 ptr 89980976
TestCpy1 42

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions