diff --git a/src/IKVM.MSBuild.Tasks/IkvmJsonParser.cs b/src/IKVM.MSBuild.Tasks/IkvmJsonParser.cs index 5aba198027..238256265c 100644 --- a/src/IKVM.MSBuild.Tasks/IkvmJsonParser.cs +++ b/src/IKVM.MSBuild.Tasks/IkvmJsonParser.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; + using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; @@ -321,7 +322,11 @@ static Dictionary CreateMemberNameDictionary(T[] members) where T static object ParseObject(Type type, string json) { +#if NETFRAMEWORK object instance = FormatterServices.GetUninitializedObject(type); +#else + object instance = RuntimeHelpers.GetUninitializedObject(type); +#endif //The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON List elems = Split(json); diff --git a/src/IKVM.Runtime/JNI/JNIEnv.cs b/src/IKVM.Runtime/JNI/JNIEnv.cs index 6d0963d143..265d629351 100644 --- a/src/IKVM.Runtime/JNI/JNIEnv.cs +++ b/src/IKVM.Runtime/JNI/JNIEnv.cs @@ -25,7 +25,9 @@ Jeroen Frijters using System.Collections.Generic; using System.Diagnostics; using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Serialization; using IKVM.ByteCode.Text; @@ -739,7 +741,11 @@ static jobject AllocObjectImpl(JNIEnv* pEnv, RuntimeJavaType wrapper) return IntPtr.Zero; } wrapper.Finish(); - return pEnv->MakeLocalRef(System.Runtime.Serialization.FormatterServices.GetUninitializedObject(wrapper.TypeAsBaseType)); +#if NETFRAMEWORK + return pEnv->MakeLocalRef(FormatterServices.GetUninitializedObject(wrapper.TypeAsBaseType)); +#else + return pEnv->MakeLocalRef(RuntimeHelpers.GetUninitializedObject(wrapper.TypeAsBaseType)); +#endif } catch (RetargetableJavaException e) { diff --git a/src/IKVM.Runtime/Java/Externs/sun/misc/Unsafe.cs b/src/IKVM.Runtime/Java/Externs/sun/misc/Unsafe.cs index f62ef262f6..16202305f3 100644 --- a/src/IKVM.Runtime/Java/Externs/sun/misc/Unsafe.cs +++ b/src/IKVM.Runtime/Java/Externs/sun/misc/Unsafe.cs @@ -1704,7 +1704,11 @@ public static object allocateInstance(object self, global::java.lang.Class cls) throw x.ToJava(); } +#if NETFRAMEWORK return FormatterServices.GetUninitializedObject(wrapper.TypeAsBaseType); +#else + return RuntimeHelpers.GetUninitializedObject(wrapper.TypeAsBaseType); +#endif } /// diff --git a/src/IKVM.Runtime/Java/Externs/sun/reflect/ReflectionFactory.cs b/src/IKVM.Runtime/Java/Externs/sun/reflect/ReflectionFactory.cs index b27ab6d627..9c4a43cc86 100644 --- a/src/IKVM.Runtime/Java/Externs/sun/reflect/ReflectionFactory.cs +++ b/src/IKVM.Runtime/Java/Externs/sun/reflect/ReflectionFactory.cs @@ -25,6 +25,8 @@ Jeroen Frijters using System.Reflection; #if !NO_REF_EMIT using System.Reflection.Emit; +using System.Runtime.CompilerServices; + #endif using System.Runtime.Serialization; using System.Security; @@ -282,7 +284,11 @@ internal SerializationConstructorAccessorImpl(global::java.lang.reflect.Construc [SecuritySafeCritical] public object newInstance(object[] args) { +#if NETFRAMEWORK var obj = FormatterServices.GetUninitializedObject(type); +#else + var obj = RuntimeHelpers.GetUninitializedObject(type); +#endif if (mw != null) mw.Invoke(obj, ConvertArgs(mw.DeclaringType.GetClassLoader(), mw.GetParameters(), args)); @@ -966,13 +972,17 @@ public object newInstance(object[] args) } - private sealed class FastSerializationConstructorAccessorImpl : global::sun.reflect.ConstructorAccessor + sealed class FastSerializationConstructorAccessorImpl : global::sun.reflect.ConstructorAccessor { - private static readonly MethodInfo GetTypeFromHandleMethod = typeof(Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(RuntimeTypeHandle) }); - private static readonly MethodInfo GetUninitializedObjectMethod = typeof(FormatterServices).GetMethod("GetUninitializedObject", new Type[] { typeof(Type) }); - private delegate object InvokeCtor(); - private InvokeCtor invoker; + static readonly MethodInfo GetTypeFromHandleMethod = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle), new[] { typeof(RuntimeTypeHandle) }); +#if NETFRAMEWORK + static readonly MethodInfo GetUninitializedObjectMethod = typeof(FormatterServices).GetMethod(nameof(FormatterServices.GetUninitializedObject), new[] { typeof(Type) }); +#else + static readonly MethodInfo GetUninitializedObjectMethod = typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.GetUninitializedObject), new[] { typeof(Type) }); +#endif + delegate object InvokeCtor(); + InvokeCtor invoker; internal FastSerializationConstructorAccessorImpl(global::java.lang.reflect.Constructor constructorToCall, global::java.lang.Class classToInstantiate) { diff --git a/src/IKVM.Runtime/RuntimeAssemblyClassLoader.cs b/src/IKVM.Runtime/RuntimeAssemblyClassLoader.cs index c276613ef0..0fc236e1d0 100644 --- a/src/IKVM.Runtime/RuntimeAssemblyClassLoader.cs +++ b/src/IKVM.Runtime/RuntimeAssemblyClassLoader.cs @@ -31,6 +31,9 @@ Jeroen Frijters using IKVM.Attributes; using IKVM.Runtime.Syntax; +using System.Runtime.CompilerServices; + + #if IMPORTER || EXPORTER using IKVM.Reflection; @@ -1253,7 +1256,11 @@ void InitializeJavaClassLoader(JavaClassLoaderConstructionInProgress jclcip, Typ [System.Security.SecuritySafeCritical] static object GetUninitializedObject(Type type) { +#if NETFRAMEWORK return FormatterServices.GetUninitializedObject(type); +#else + return RuntimeHelpers.GetUninitializedObject(type); +#endif } static void LoadCustomClassLoaderRedirects(RuntimeContext context) diff --git a/src/IKVM.Tools.Exporter/IkvmExporterContext.NetCore.cs b/src/IKVM.Tools.Exporter/IkvmExporterContext.NetCore.cs index f263decfd8..2188bf4fd4 100644 --- a/src/IKVM.Tools.Exporter/IkvmExporterContext.NetCore.cs +++ b/src/IKVM.Tools.Exporter/IkvmExporterContext.NetCore.cs @@ -1,17 +1,12 @@ #if NETCOREAPP using System; -using System.IO; using System.Reflection; using System.Runtime.Loader; -using System.Runtime.Serialization.Formatters.Binary; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyModel.Resolution; - -using System.Text.Json; - namespace IKVM.Tools.Exporter {