From a415a30cb2f3633e950ce9ef9f4fc286ac391e2b Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 3 Dec 2020 00:08:02 +0100 Subject: [PATCH 1/4] Pull GetUninitializedObject from RuntimeHelpers type on netcore --- src/Mono.Android/Android.Runtime/ConstructorBuilder.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs index 3596695c4b9..dff94cf09ee 100644 --- a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs +++ b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs @@ -6,8 +6,13 @@ using System.Threading; namespace Android.Runtime { - internal class ConstructorBuilder { - static MethodInfo newobject = typeof (System.Runtime.Serialization.FormatterServices).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; + internal static class ConstructorBuilder { + static readonly MethodInfo newobject = +#if NETCOREAPP3_1_OR_GREATER + typ##eof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; +#else + typeof (System.Runtime.Serialization.FormatterServices).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; +#endif static MethodInfo gettype = typeof (System.Type).GetMethod ("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static)!; static FieldInfo handlefld = typeof (Java.Lang.Object).GetField ("handle", BindingFlags.NonPublic | BindingFlags.Instance)!; static FieldInfo Throwable_handle = typeof (Java.Lang.Throwable).GetField ("handle", BindingFlags.NonPublic | BindingFlags.Instance)!; From d1a25a7c57f44870ec6b62403feba26b8914ba79 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 3 Dec 2020 12:26:43 +0100 Subject: [PATCH 2/4] Try different define --- src/Mono.Android/Android.Runtime/ConstructorBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs index dff94cf09ee..cb939dd1179 100644 --- a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs +++ b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs @@ -8,10 +8,10 @@ namespace Android.Runtime { internal static class ConstructorBuilder { static readonly MethodInfo newobject = -#if NETCOREAPP3_1_OR_GREATER - typ##eof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; -#else +#if NETFRAMEWORK typeof (System.Runtime.Serialization.FormatterServices).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; +#else + typ##eof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; #endif static MethodInfo gettype = typeof (System.Type).GetMethod ("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static)!; static FieldInfo handlefld = typeof (Java.Lang.Object).GetField ("handle", BindingFlags.NonPublic | BindingFlags.Instance)!; From 1cf9975be54d0da369233a4659bac17eb42c3a99 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 3 Dec 2020 13:14:16 +0100 Subject: [PATCH 3/4] Another try --- src/Mono.Android/Android.Runtime/ConstructorBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs index cb939dd1179..79dd94a92fa 100644 --- a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs +++ b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs @@ -8,7 +8,7 @@ namespace Android.Runtime { internal static class ConstructorBuilder { static readonly MethodInfo newobject = -#if NETFRAMEWORK +#if NETFRAMEWORK || NET_2_0 typeof (System.Runtime.Serialization.FormatterServices).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; #else typ##eof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; From 8c1b15e30dd6b667ee71d45160f0920f5a966c47 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Thu, 3 Dec 2020 13:36:16 +0100 Subject: [PATCH 4/4] Bingo --- src/Mono.Android/Android.Runtime/ConstructorBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs index 79dd94a92fa..ab14006ca52 100644 --- a/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs +++ b/src/Mono.Android/Android.Runtime/ConstructorBuilder.cs @@ -11,7 +11,7 @@ internal static class ConstructorBuilder { #if NETFRAMEWORK || NET_2_0 typeof (System.Runtime.Serialization.FormatterServices).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; #else - typ##eof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; + typeof (System.Runtime.CompilerServices.RuntimeHelpers).GetMethod ("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static)!; #endif static MethodInfo gettype = typeof (System.Type).GetMethod ("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static)!; static FieldInfo handlefld = typeof (Java.Lang.Object).GetField ("handle", BindingFlags.NonPublic | BindingFlags.Instance)!;