System.Reflection.ResolveField isn't valid for fields of generic types, despite the same metadata token returning the same field for each generic type used. It will raise System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
Not sure how to fix, maybe pass generic specification type from methodbase if it exists? Problem occurs if anyone uses this to hook method of a generic - [HarmonyPatch(typeof(SomeGenericClass<>), "SomeNormalMethod")] - same behavior if you have generic type specifier included as well. Maybe can error on the former gracefully, and handle the latter.
Hacky change for my use that specifies the generics I know of works, but can't PR that - methodModule.ResolveField((int)opArg, new Type[] { typeof(SomeClassTypeSpecifierForThatGeneric) }, new Type[] { });
System.Reflection.ResolveField isn't valid for fields of generic types, despite the same metadata token returning the same field for each generic type used. It will raise
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
https://github.com/BepInEx/Il2CppInterop/blob/126c5d07093b0b1caa6ae7162cae5923ed09e4be/Il2CppInterop.Common/Il2CppInteropUtils.cs#L8![image](https://user-images.githubusercontent.com/56001276/221382784-cdc30460-5685-4abc-bfda-aa191972358d.png)
Not sure how to fix, maybe pass generic specification type from methodbase if it exists? Problem occurs if anyone uses this to hook method of a generic -
[HarmonyPatch(typeof(SomeGenericClass<>), "SomeNormalMethod")]
- same behavior if you have generic type specifier included as well. Maybe can error on the former gracefully, and handle the latter.Hacky change for my use that specifies the generics I know of works, but can't PR that -
methodModule.ResolveField((int)opArg, new Type[] { typeof(SomeClassTypeSpecifierForThatGeneric) }, new Type[] { });