@@ -359,18 +359,36 @@ static Type GetPeerType ([DynamicallyAccessedMembers (Constructors)] Type type)
359359 static Type ? GetInvokerType ( Type type )
360360 {
361361 const string suffix = "Invoker" ;
362+
363+ // https://github.com/xamarin/xamarin-android/blob/5472eec991cc075e4b0c09cd98a2331fb93aa0f3/src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs#L176-L186
364+ const string assemblyGetTypeMessage = "'Invoker' types are preserved by the MarkJavaObjects trimmer step." ;
365+ const string makeGenericTypeMessage = "Generic 'Invoker' types are preserved by the MarkJavaObjects trimmer step." ;
366+
367+ [ UnconditionalSuppressMessage ( "Trimming" , "IL2026" , Justification = assemblyGetTypeMessage ) ]
368+ [ UnconditionalSuppressMessage ( "Trimming" , "IL2073" , Justification = assemblyGetTypeMessage ) ]
369+ [ return : DynamicallyAccessedMembers ( Constructors ) ]
370+ static Type ? AssemblyGetType ( Assembly assembly , string typeName ) =>
371+ assembly . GetType ( typeName ) ;
372+
373+ // FIXME: https://github.com/xamarin/java.interop/issues/1192
374+ [ UnconditionalSuppressMessage ( "Trimming" , "IL2055" , Justification = makeGenericTypeMessage ) ]
375+ [ UnconditionalSuppressMessage ( "AOT" , "IL3050" , Justification = makeGenericTypeMessage ) ]
376+ [ return : DynamicallyAccessedMembers ( Constructors ) ]
377+ static Type MakeGenericType ( Type type , Type [ ] arguments ) =>
378+ type . MakeGenericType ( arguments ) ;
379+
362380 Type [ ] arguments = type . GetGenericArguments ( ) ;
363381 if ( arguments . Length == 0 )
364- return type . Assembly . GetType ( type + suffix ) ;
382+ return AssemblyGetType ( type . Assembly , type + suffix ) ;
365383 Type definition = type . GetGenericTypeDefinition ( ) ;
366384 int bt = definition . FullName ! . IndexOf ( "`" , StringComparison . Ordinal ) ;
367385 if ( bt == - 1 )
368386 throw new NotSupportedException ( "Generic type doesn't follow generic type naming convention! " + type . FullName ) ;
369- Type ? suffixDefinition = definition . Assembly . GetType (
387+ Type ? suffixDefinition = AssemblyGetType ( definition . Assembly ,
370388 definition . FullName . Substring ( 0 , bt ) + suffix + definition . FullName . Substring ( bt ) ) ;
371389 if ( suffixDefinition == null )
372390 return null ;
373- return suffixDefinition . MakeGenericType ( arguments ) ;
391+ return MakeGenericType ( suffixDefinition , arguments ) ;
374392 }
375393
376394 public object ? CreateValue (
@@ -634,9 +652,17 @@ public JniValueMarshaler GetValueMarshaler (
634652
635653 static JniValueMarshaler GetObjectArrayMarshaler ( Type elementType )
636654 {
655+ const string makeGenericMethodMessage = "This code path is not used in Android projects." ;
656+
657+ // FIXME: https://github.com/xamarin/java.interop/issues/1192
658+ [ UnconditionalSuppressMessage ( "Trimming" , "IL2060" , Justification = makeGenericMethodMessage ) ]
659+ [ UnconditionalSuppressMessage ( "AOT" , "IL3050" , Justification = makeGenericMethodMessage ) ]
660+ static MethodInfo MakeGenericMethod ( MethodInfo method , Type type ) =>
661+ method . MakeGenericMethod ( type ) ;
662+
637663 Func < JniValueMarshaler > indirect = GetObjectArrayMarshalerHelper < object > ;
638- var reifiedMethodInfo = indirect . Method . GetGenericMethodDefinition ( )
639- . MakeGenericMethod ( elementType ) ;
664+ var reifiedMethodInfo = MakeGenericMethod (
665+ indirect . Method . GetGenericMethodDefinition ( ) , elementType ) ;
640666 Func < JniValueMarshaler > direct = ( Func < JniValueMarshaler > ) Delegate . CreateDelegate ( typeof ( Func < JniValueMarshaler > ) , reifiedMethodInfo ) ;
641667 return direct ( ) ;
642668 }
0 commit comments