ltrzesniewski / InlineIL.Fody

Inject arbitrary IL code at compile time.
MIT License
240 stars 17 forks source link

OutOfMemoryException due to an invalid IL produced for accessing to the field in a generic class #5

Closed rameel closed 5 years ago

rameel commented 5 years ago

Accessing to the member in a generic class produces an invalid IL that makes the Runtime throws an OutOfMemoryException

public class Program
{
    public static void Main() => Console.WriteLine(Sample<int>.GetValue());
}
public static class Sample<T>
{
    public static readonly int Value = 10;

    public static int GetValue()
    {
        Ldsfld(new FieldRef(typeof(Sample<T>), nameof(Value)));
        return IL.Return<int>();
    }
}

.NET Core 2.2.1 (SDK 2.2.102)

ltrzesniewski commented 5 years ago

Thanks for the report! It looks like the generic parameter is not propagated properly... I added a failing test in 619028e6ae261014e76cea9ac6f65bc7d9e88e98 for now, I'll fix the issue later.

ltrzesniewski commented 5 years ago

Fixed in v1.0.3.

rameel commented 5 years ago

Thanks!