Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect Reflection & TypedReference behavior in AOT mode. #18364

@EgorBo

Description

@EgorBo

The following program prints 4096 in JIT mode and 1234 in AOT mode (for both legacy and netcore mono runtimes). The correct value is 4096 so it's something wrong with AOT.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;

public class Program
{
    public static void Main()
    {
        Console.WriteLine(SetValueDirect());
    }

    struct TestFields
    {
        public int MaxValue;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static int SetValueDirect()
    {
        TestFields fields = new TestFields { MaxValue = 1234 };
        FieldInfo info = typeof(TestFields).GetField("MaxValue");
        TypedReference reference = __makeref(fields);
        info.SetValueDirect(reference, 4096);
        return fields.MaxValue;
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions