diff --git a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs index da27a3b04f2..fafdc00e8b9 100644 --- a/src/Mono.Android/Android.Runtime/AndroidRuntime.cs +++ b/src/Mono.Android/Android.Runtime/AndroidRuntime.cs @@ -391,6 +391,7 @@ protected override IEnumerable GetSimpleReferences (Type type) // See ExportAttribute.cs [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "Mono.Android.Export.dll is preserved when [Export] is used via [DynamicDependency].")] + [UnconditionalSuppressMessage ("Trimming", "IL2075", Justification = "Mono.Android.Export.dll is preserved when [Export] is used via [DynamicDependency].")] static Delegate CreateDynamicCallback (MethodInfo method) { if (dynamic_callback_gen == null) { @@ -479,10 +480,20 @@ static bool CallRegisterMethodByIndex (JniNativeMethodRegistrationArguments argu } } - public override void RegisterNativeMembers (JniType nativeClass, Type type, string? methods) => + public override void RegisterNativeMembers ( + JniType nativeClass, + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] + Type type, + string? methods) => RegisterNativeMembers (nativeClass, type, methods.AsSpan ()); - public void RegisterNativeMembers (JniType nativeClass, Type type, ReadOnlySpan methods) + [UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Type.GetType() can never statically know the string value parsed from parameter 'methods'.")] + [UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = "Delegate.CreateDelegate() can never statically know the string value parsed from parameter 'methods'.")] + [UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "Delegate.CreateDelegate() can never statically know the string value parsed from parameter 'methods'.")] + public void RegisterNativeMembers ( + JniType nativeClass, + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type type, + ReadOnlySpan methods) { try { if (methods.IsEmpty) { diff --git a/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs b/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs index 0110165e1be..ca0ca41d701 100644 --- a/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs +++ b/src/Mono.Android/Java.Interop/JavaObjectExtensions.cs @@ -122,6 +122,7 @@ static IJavaObject CastClass (IJavaObject instance, Type resultType) // typeof(Foo) -> FooInvoker // typeof(Foo<>) -> FooInvoker`1 [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "*Invoker types are preserved by the MarkJavaObjects linker step.")] + [UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = "*Invoker types are preserved by the MarkJavaObjects linker step.")] internal static Type? GetInvokerType (Type type) { const string suffix = "Invoker"; diff --git a/src/Mono.Android/Java.Interop/TypeManager.cs b/src/Mono.Android/Java.Interop/TypeManager.cs index 6d4556bf7a4..09eb92959f2 100644 --- a/src/Mono.Android/Java.Interop/TypeManager.cs +++ b/src/Mono.Android/Java.Interop/TypeManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Linq; using System.Runtime.CompilerServices; @@ -116,6 +117,7 @@ internal static bool ActivationEnabled { } #endif // !JAVA_INTEROP + [UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Type.GetType() can never statically know the string value from parameter 'signature'.")] static Type[] GetParameterTypes (string? signature) { if (String.IsNullOrEmpty (signature)) @@ -127,6 +129,7 @@ static Type[] GetParameterTypes (string? signature) return result; } + [UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Type.GetType() can never statically know the string value from parameter 'typename_ptr'.")] static void n_Activate (IntPtr jnienv, IntPtr jclass, IntPtr typename_ptr, IntPtr signature_ptr, IntPtr jobject, IntPtr parameters_ptr) { var o = Java.Lang.Object.PeekObject (jobject); @@ -163,6 +166,7 @@ static void n_Activate (IntPtr jnienv, IntPtr jclass, IntPtr typename_ptr, IntPt Activate (jobject, cinfo, parms); } + [UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "RuntimeHelpers.GetUninitializedObject() does not statically know the return value from ConstructorInfo.DeclaringType.")] internal static void Activate (IntPtr jobject, ConstructorInfo cinfo, object? []? parms) { try { @@ -257,6 +261,8 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership return CreateInstance (handle, transfer, null); } + [UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = "TypeManager.CreateProxy() does not statically know the value of the 'type' local variable.")] + [UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "TypeManager.CreateProxy() does not statically know the value of the 'type' local variable.")] internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership transfer, Type? targetType) { Type? type = null; @@ -318,7 +324,11 @@ internal static IJavaPeerable CreateInstance (IntPtr handle, JniHandleOwnership static readonly Type[] XAConstructorSignature = new Type [] { typeof (IntPtr), typeof (JniHandleOwnership) }; static readonly Type[] JIConstructorSignature = new Type [] { typeof (JniObjectReference).MakeByRefType (), typeof (JniObjectReferenceOptions) }; - internal static object CreateProxy (Type type, IntPtr handle, JniHandleOwnership transfer) + internal static object CreateProxy ( + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] + Type type, + IntPtr handle, + JniHandleOwnership transfer) { // Skip Activator.CreateInstance() as that requires public constructors, // and we want to hide some constructors for sanity reasons.