Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

Commit a790143

Browse files
[Java.Interop] supress one instance of IL2072
Context: dotnet/android#8805 When testing new defaults for `TrimMode=full` in xamarin/xamarin-android: dotnet new android dotnet build -c Release -r android-arm64 Results in a single warning: external\Java.Interop\src\Java.Interop\Java.Interop\JniRuntime.JniValueManager.cs(890,4): Trim analysis warning IL2072: Java.Interop.ProxyValueMarshaler.CreateGenericObjectReferenceArgumentState(Object, ParameterAttributes): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'Java.Interop.JniRuntime.JniValueManager.GetValueMarshaler(Type)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. This appears to be a case where the trimmer (ILLink's analyzers) can detect a problem where the Roslyn analyzer could not. It is generally possible for the trimmer to discover some new warning, as it has a complete view of the final code. This appears to be similar to some other places we used the justification: [UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "This code path is not used in Android projects.")]
1 parent 3436a30 commit a790143

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,16 @@ sealed class ProxyValueMarshaler : JniValueMarshaler<object?> {
882882

883883
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]object? value, ParameterAttributes synchronize)
884884
{
885+
[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "This code path is not used in Android projects.")]
886+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)]
887+
static Type GetType (object value) => value.GetType ();
888+
885889
if (value == null)
886890
return new JniValueMarshalerState ();
887891

888892
var jvm = JniEnvironment.Runtime;
889893

890-
var vm = jvm.ValueManager.GetValueMarshaler (value.GetType ());
894+
var vm = jvm.ValueManager.GetValueMarshaler (GetType (value));
891895
if (vm != Instance) {
892896
var s = vm.CreateObjectReferenceArgumentState (value, synchronize);
893897
return new JniValueMarshalerState (s, vm);

0 commit comments

Comments
 (0)