diff --git a/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs b/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs index ef7c40e4..08e09523 100644 --- a/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs +++ b/Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs @@ -84,8 +84,8 @@ public T Unbox() where T : unmanaged private static readonly Type[] _intPtrTypeArray = { typeof(IntPtr) }; private static readonly MethodInfo _getUninitializedObject = typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.GetUninitializedObject))!; private static readonly MethodInfo _getTypeFromHandle = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle))!; - private static readonly MethodInfo _createGCHandle = typeof(Il2CppObjectBase).GetMethod(nameof(CreateGCHandle))!; - private static readonly FieldInfo _isWrapped = typeof(Il2CppObjectBase).GetField(nameof(isWrapped))!; + private static readonly MethodInfo _createGCHandle = typeof(Il2CppObjectBase).GetMethod(nameof(CreateGCHandle), BindingFlags.Instance | BindingFlags.NonPublic)!; + private static readonly FieldInfo _isWrapped = typeof(Il2CppObjectBase).GetField(nameof(isWrapped), BindingFlags.Instance | BindingFlags.NonPublic)!; internal static class InitializerStore { @@ -112,7 +112,7 @@ private static Func Create() // However, it could be be user-made or implicit // In that case we set the GCHandle and then call the ctor and let GC destroy any objects created by DerivedConstructorPointer - // var obj = (T)FormatterServices.GetUninitializedObject(type); + // var obj = (T)RuntimeHelpers.GetUninitializedObject(type); il.Emit(OpCodes.Ldtoken, type); il.Emit(OpCodes.Call, _getTypeFromHandle); il.Emit(OpCodes.Call, _getUninitializedObject); @@ -126,7 +126,7 @@ private static Func Create() // obj.isWrapped = true; il.Emit(OpCodes.Dup); il.Emit(OpCodes.Ldc_I4_1); - il.Emit(OpCodes.Stsfld, _isWrapped); + il.Emit(OpCodes.Stfld, _isWrapped); var parameterlessConstructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes); if (parameterlessConstructor != null)