From 8284538b56c2a86ae58945706d6b2e79b7f22a61 Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Wed, 20 May 2026 15:22:02 +0200 Subject: [PATCH 1/5] Update ValueManagers --- external/Java.Interop | 2 +- .../Android.Runtime/AndroidRuntime.cs | 6 +++- .../JavaMarshalValueManager.cs | 35 +++---------------- .../SimpleValueManager.cs | 35 ------------------- 4 files changed, 10 insertions(+), 68 deletions(-) diff --git a/external/Java.Interop b/external/Java.Interop index d3636b45ba8..f7fa39e2835 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit d3636b45ba8823f2ed96572f9f550c458ba79099 +Subproject commit f7fa39e2835086b2f000639b5b9f5d0ceeb76505 diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index d32e1993f1b..2d07a92b34e 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -832,7 +832,11 @@ internal void RemovePeer (IJavaPeerable value, IntPtr hash) return null; } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object? []? argumentValues) + public override void ActivatePeer ( + JniObjectReference reference, + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, + ConstructorInfo cinfo, + object?[]? argumentValues) { Java.Interop.TypeManager.Activate (reference.Handle, cinfo, argumentValues); } diff --git a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs index 210f6f343a0..c53c5f567c9 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs @@ -249,39 +249,12 @@ public override void FinalizePeer (IJavaPeerable value) value.Finalized (); } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) + public override void ActivatePeer (JniObjectReference reference, [DynamicallyAccessedMembers (Constructors)] Type type, ConstructorInfo cinfo, object?[]? argumentValues) { - try { - ActivateViaReflection (reference, cinfo, argumentValues); - } catch (Exception e) { - var m = string.Format ( - CultureInfo.InvariantCulture, - "Could not activate {{ PeerReference={0} IdentityHashCode=0x{1} Java.Type={2} }} for managed type '{3}'.", - reference, - GetJniIdentityHashCode (reference).ToString ("x", CultureInfo.InvariantCulture), - JniEnvironment.Types.GetJniTypeNameFromInstance (reference), - cinfo.DeclaringType?.FullName); - Debug.WriteLine (m); - - throw new NotSupportedException (m, e); - } - } - - void ActivateViaReflection (JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - var declType = GetDeclaringType (cinfo); - -#pragma warning disable IL2072 - var self = (IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (declType); -#pragma warning restore IL2072 - self.SetPeerReference (reference); - - cinfo.Invoke (self, argumentValues); + if (RuntimeFeature.TrimmableTypeMap) + throw new PlatformNotSupportedException ("Activating Java peers is not supported when trimming is enabled."); - [UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "🤷‍♂️")] - [return: DynamicallyAccessedMembers (Constructors)] - Type GetDeclaringType (ConstructorInfo cinfo) => - cinfo.DeclaringType ?? throw new NotSupportedException ("Do not know the type to create!"); + base.ActivatePeer (reference, type, cinfo, argumentValues); } public override List GetSurfacedPeers () diff --git a/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs index 57d8ef5f84d..bcccf6d6fd1 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs @@ -207,41 +207,6 @@ public override void FinalizePeer (IJavaPeerable value) value.Finalized (); } - public override void ActivatePeer (IJavaPeerable? self, JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - try { - ActivateViaReflection (reference, cinfo, argumentValues); - } catch (Exception e) { - var m = string.Format ( - CultureInfo.InvariantCulture, - "Could not activate {{ PeerReference={0} IdentityHashCode=0x{1} Java.Type={2} }} for managed type '{3}'.", - reference, - GetJniIdentityHashCode (reference).ToString ("x", CultureInfo.InvariantCulture), - JniEnvironment.Types.GetJniTypeNameFromInstance (reference), - cinfo.DeclaringType?.FullName); - Debug.WriteLine (m); - - throw new NotSupportedException (m, e); - } - } - - void ActivateViaReflection (JniObjectReference reference, ConstructorInfo cinfo, object?[]? argumentValues) - { - var declType = GetDeclaringType (cinfo); - -#pragma warning disable IL2072 - var self = (IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (declType); -#pragma warning restore IL2072 - self.SetPeerReference (reference); - - cinfo.Invoke (self, argumentValues); - - [UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "🤷‍♂️")] - [return: DynamicallyAccessedMembers (Constructors)] - Type GetDeclaringType (ConstructorInfo cinfo) => - cinfo.DeclaringType ?? throw new NotSupportedException ("Do not know the type to create!"); - } - public override List GetSurfacedPeers () { if (RegisteredInstances == null) From 303f5f65391757981766ba8a95f92f542510b98a Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Thu, 21 May 2026 09:43:12 +0200 Subject: [PATCH 2/5] Use reviewed Java.Interop ActivatePeer API Update the Java.Interop submodule to the reviewed ActivatePeer signature change and clean up the AndroidRuntime override formatting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- external/Java.Interop | 2 +- src/Mono.Android/Android.Runtime/AndroidRuntime.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/external/Java.Interop b/external/Java.Interop index f7fa39e2835..7d8f89db77b 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit f7fa39e2835086b2f000639b5b9f5d0ceeb76505 +Subproject commit 7d8f89db77bf17c74921bc35d95876e2509d0274 diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index 2d07a92b34e..918b8377b54 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -836,7 +836,7 @@ public override void ActivatePeer ( JniObjectReference reference, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, ConstructorInfo cinfo, - object?[]? argumentValues) + object?[]? argumentValues) { Java.Interop.TypeManager.Activate (reference.Handle, cinfo, argumentValues); } From fe87e1441db17f76e81f6afd7dab7b2a0a707f8b Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Thu, 21 May 2026 10:09:28 +0200 Subject: [PATCH 3/5] Remove Java.Interop submodule bump Keep this Android change independent until the Java.Interop ActivatePeer API update flows into dotnet/android through Maestro. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index 7d8f89db77b..d3636b45ba8 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 7d8f89db77bf17c74921bc35d95876e2509d0274 +Subproject commit d3636b45ba8823f2ed96572f9f550c458ba79099 From 36d547285fd3637870253739cd0b856763f83323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Rozs=C3=ADval?= Date: Thu, 21 May 2026 10:09:43 +0200 Subject: [PATCH 4/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../Microsoft.Android.Runtime/JavaMarshalValueManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs index c53c5f567c9..e07fda8e225 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs @@ -252,7 +252,7 @@ public override void FinalizePeer (IJavaPeerable value) public override void ActivatePeer (JniObjectReference reference, [DynamicallyAccessedMembers (Constructors)] Type type, ConstructorInfo cinfo, object?[]? argumentValues) { if (RuntimeFeature.TrimmableTypeMap) - throw new PlatformNotSupportedException ("Activating Java peers is not supported when trimming is enabled."); + throw new PlatformNotSupportedException ("Activating Java peers is not supported when TrimmableTypeMap is enabled."); base.ActivatePeer (reference, type, cinfo, argumentValues); } From 0a37e7573e6ad77113606357ae69ab460fdc1443 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 02:53:16 +0000 Subject: [PATCH 5/5] Bump external/Java.Interop from `d3636b4` to `d546a08` Bumps [external/Java.Interop](https://github.com/dotnet/java-interop) from `d3636b4` to `d546a08`. - [Commits](https://github.com/dotnet/java-interop/compare/d3636b45ba8823f2ed96572f9f550c458ba79099...d546a083f3139243243959fbf1d9b7d35f6c2cbf) --- updated-dependencies: - dependency-name: external/Java.Interop dependency-version: d546a083f3139243243959fbf1d9b7d35f6c2cbf dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index d3636b45ba8..d546a083f31 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit d3636b45ba8823f2ed96572f9f550c458ba79099 +Subproject commit d546a083f3139243243959fbf1d9b7d35f6c2cbf