diff --git a/external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniRuntime.JniTypeManagerTests.cs b/external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniRuntime.JniTypeManagerTests.cs index 1994a073b72..feb00c0e8e4 100644 --- a/external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniRuntime.JniTypeManagerTests.cs +++ b/external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniRuntime.JniTypeManagerTests.cs @@ -10,6 +10,7 @@ namespace Java.InteropTests { public class JniRuntimeJniTypeManagerTests : JavaVMFixture { [Test] + [Category ("TrimmableTypeMapUnsupported")] [RequiresDynamicCode ("This test uses ReflectionJniTypeManager, which is reflection-based and not NativeAOT-compatible.")] [RequiresUnreferencedCode ("This test uses ReflectionJniTypeManager, which is reflection-based and not trimming-compatible.")] public void GetInvokerType () diff --git a/src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs b/src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs index 0a8a698a6a4..50f7c22d161 100644 --- a/src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs +++ b/src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs @@ -37,7 +37,7 @@ namespace Microsoft.Android.Sdk.TrimmableTypeMap; /// // or: null; // no activation /// // or: throw new NotSupportedException(...); // open generic /// -/// // JniName / TargetType / InvokerType are supplied by the base JavaPeerProxy constructor. +/// // JniName / TargetType are supplied by the base JavaPeerProxy constructor. /// /// // UCO wrappers — [UnmanagedCallersOnly] entry points for JNI native methods (ACWs only): /// public static void n_OnCreate_uco_0(IntPtr jnienv, IntPtr self, IntPtr p0) @@ -731,22 +731,20 @@ void EmitProxyType (JavaPeerProxyData proxy, Dictionary sig.MethodSignature (isInstanceMethod: true).Parameters (3, + sig => sig.MethodSignature (isInstanceMethod: true).Parameters (2, rt => rt.Void (), p => { p.AddParameter ().Type ().String (); p.AddParameter ().Type ().Type (_systemTypeRef, false); - p.AddParameter ().Type ().Type (_systemTypeRef, false); })); } else { var genericProxyBase = _pe.MakeGenericTypeSpec (_javaPeerProxyRef, targetTypeRef); proxyBaseType = genericProxyBase; baseCtorRef = _pe.AddMemberRef (genericProxyBase, ".ctor", - sig => sig.MethodSignature (isInstanceMethod: true).Parameters (2, + sig => sig.MethodSignature (isInstanceMethod: true).Parameters (1, rt => rt.Void (), p => { p.AddParameter ().Type ().String (); - p.AddParameter ().Type ().Type (_systemTypeRef, false); })); } @@ -762,8 +760,8 @@ void EmitProxyType (JavaPeerProxyData proxy, Dictionary sig.MethodSignature (isInstanceMethod: true).Parameters (0, rt => rt.Void (), p => { }), @@ -771,18 +769,12 @@ void EmitProxyType (JavaPeerProxyData proxy, Dictionary @@ -72,13 +69,6 @@ protected JavaPeerProxy ( /// public Type TargetType { get; } - /// - /// Gets the invoker type for interfaces and abstract classes. - /// Returns null for concrete types that can be directly instantiated. - /// - [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - public Type? InvokerType { get; } - /// /// Gets a factory for creating containers (arrays, collections) of the target type. /// Enables AOT-safe creation of generic collections without MakeGenericType(). @@ -148,9 +138,7 @@ public abstract class JavaPeerProxy< > : JavaPeerProxy where T : class, IJavaPeerable { protected JavaPeerProxy ( - string jniName, - [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - Type? invokerType) : base (jniName, typeof (T), invokerType) + string jniName) : base (jniName, typeof (T)) { } diff --git a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs index 145d253050d..a144454031d 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs @@ -493,15 +493,6 @@ internal static bool TargetTypeMatches (Type targetType, Type proxyTargetType) return targetType.IsAssignableFrom (proxyTargetType); } - /// - /// Gets the invoker type for an interface or abstract class from the proxy attribute. - /// - [return: DynamicallyAccessedMembers (Constructors)] - internal Type? GetInvokerType (Type type) - { - return GetProxyForManagedType (type)?.InvokerType; - } - /// /// Gets the container factory for a type from its proxy attribute. /// Used for AOT-safe array/collection/dictionary creation. diff --git a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapTypeManager.cs b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapTypeManager.cs index 5ff5f6d4a9d..2350f8440fc 100644 --- a/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapTypeManager.cs +++ b/src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapTypeManager.cs @@ -96,12 +96,10 @@ protected override IEnumerable GetSimpleReferences (Type type) protected override Type? GetInvokerTypeCore (Type type) { - var invokerType = TrimmableTypeMap.Instance.GetInvokerType (type); - if (invokerType != null) { - return invokerType; - } - - return base.GetInvokerTypeCore (type); + throw new NotSupportedException ( + $"GetInvokerTypeCore should not be called in the trimmable typemap path. " + + $"Peers for '{type.FullName}' are activated through the generated {nameof (JavaPeerProxy)}.CreateInstance, " + + $"so invoker types are never used."); } protected override IReadOnlyList? GetStaticMethodFallbackTypesCore (string jniSimpleReference) diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaPeerProxyTests.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaPeerProxyTests.cs index 35ffd2c3f8d..b83138acb70 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaPeerProxyTests.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaPeerProxyTests.cs @@ -18,17 +18,15 @@ public void Constructor_StoresJniNameAndTargetType () Assert.AreEqual ("custom/ExplicitName", proxy.JniName); Assert.AreEqual (typeof (ProxyTestPeer), proxy.TargetType); - Assert.IsNull (proxy.InvokerType); } [Test] - public void Constructor_StoresInvokerType () + public void GenericConstructor_StoresJniNameAndTargetType () { - var proxy = new InvokerProxy (); + var proxy = new GenericProxy (); - Assert.AreEqual ("custom/InvokerProxy", proxy.JniName); + Assert.AreEqual ("custom/GenericProxy", proxy.JniName); Assert.AreEqual (typeof (ProxyTestPeer), proxy.TargetType); - Assert.AreEqual (typeof (ProxyTestPeerInvoker), proxy.InvokerType); } } @@ -45,32 +43,20 @@ public ProxyTestPeer (IntPtr handle, JniHandleOwnership transfer) } } - sealed class ProxyTestPeerInvoker : Java.Lang.Object - { - public ProxyTestPeerInvoker () - { - } - - public ProxyTestPeerInvoker (IntPtr handle, JniHandleOwnership transfer) - : base (handle, transfer) - { - } - } - sealed class ExplicitNameProxy : JavaPeerProxy { public ExplicitNameProxy () - : base ("custom/ExplicitName", typeof (ProxyTestPeer), invokerType: null) + : base ("custom/ExplicitName", typeof (ProxyTestPeer)) { } public override IJavaPeerable? CreateInstance (IntPtr handle, JniHandleOwnership transfer) => null; } - sealed class InvokerProxy : JavaPeerProxy + sealed class GenericProxy : JavaPeerProxy { - public InvokerProxy () - : base ("custom/InvokerProxy", typeof (ProxyTestPeerInvoker)) + public GenericProxy () + : base ("custom/GenericProxy") { }