Skip to content

Commit 45437e2

Browse files
[Java.Interop] suppress IL3050 with #pragma (#1201)
Context: dotnet/android#8758 (comment) Context: #1192 Context: 2197579 In 7d1e705 and b8f6f88, we suppressed IL3050, an AOT-related warning with: // FIXME: #1192 [UnconditionalSuppressMessage ("AOT", "IL3050")] // Problematic code here We don't immediately *plan* to support NativeAOT on Android in .NET 9, so it would be nice if we could suppress the warning *for now*. However, if/when anyone tried to use this code in a NativeAOT context such as 2197579, they *should* get a warning (but didn't). We should instead use: // FIXME: #1192 #pragma warning disable IL3050 // Problematic code here #pragma warning restore IL3050 This will prevent us from introducing new `IL3050` and related warnings, but if anyone consumes `Java.Interop.dll` from NativeAOT they will see the warning. This (re-)introduces IL3050 warnings in the build for `samples/Hello-NativeAOTFromJNI` (2197579): % dotnet publish -c Release -r osx-x64 … …/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs(665): AOT analysis warning IL3050: Java.Interop.JniRuntime.JniValueManager.<GetObjectArrayMarshaler>g__MakeGenericMethod|41_0(MethodInfo,Type): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. …/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs(381): AOT analysis warning IL3050: Java.Interop.JniRuntime.JniValueManager.<GetInvokerType>g__MakeGenericType|31_1(Type,Type[]): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. …/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs(789): AOT analysis warning IL3050: Java.Interop.JavaPeerableValueMarshaler.CreateParameterToManagedExpression(JniValueMarshalerContext,ParameterExpression,ParameterAttributes,Type): Using member 'System.Linq.Expressions.Expression.Call(Expression,String,Type[],Expression[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Calling a generic method requires dynamic code generation. This can be suppressed if the method is not generic. …/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs(284): AOT analysis warning IL3050: Java.Interop.JniRuntime.JniTypeManager.MakeGenericType(Type,Type): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. …/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs(277): AOT analysis warning IL3050: Java.Interop.JniRuntime.JniTypeManager.MakeArrayType(Type): Using member 'System.Type.MakeArrayType()' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available.
1 parent 1c9c8c9 commit 45437e2

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,18 @@ protected virtual IEnumerable<string> GetSimpleReferences (Type type)
271271
static readonly Type[] EmptyTypeArray = Array.Empty<Type> ();
272272
const string NotUsedInAndroid = "This code path is not used in Android projects.";
273273

274-
// FIXME: https://github.com/xamarin/java.interop/issues/1192
275-
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = NotUsedInAndroid)]
276-
static Type MakeArrayType (Type type) => type.MakeArrayType ();
274+
static Type MakeArrayType (Type type) =>
275+
// FIXME: https://github.com/xamarin/java.interop/issues/1192
276+
#pragma warning disable IL3050
277+
type.MakeArrayType ();
278+
#pragma warning restore IL3050
277279

278-
// FIXME: https://github.com/xamarin/java.interop/issues/1192
279280
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = NotUsedInAndroid)]
280-
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = NotUsedInAndroid)]
281-
static Type MakeGenericType (Type type, Type arrayType) => type.MakeGenericType (arrayType);
281+
static Type MakeGenericType (Type type, Type arrayType) =>
282+
// FIXME: https://github.com/xamarin/java.interop/issues/1192
283+
#pragma warning disable IL3050
284+
type.MakeGenericType (arrayType);
285+
#pragma warning restore IL3050
282286

283287
[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "Types returned here should be preserved via other means.")]
284288
[return: DynamicallyAccessedMembers (MethodsConstructorsInterfaces)]

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,16 @@ static Type GetPeerType ([DynamicallyAccessedMembers (Constructors)] Type type)
370370
static Type? AssemblyGetType (Assembly assembly, string typeName) =>
371371
assembly.GetType (typeName);
372372

373-
// FIXME: https://github.com/xamarin/java.interop/issues/1192
374373
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = makeGenericTypeMessage)]
375-
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = makeGenericTypeMessage)]
376374
[return: DynamicallyAccessedMembers (Constructors)]
377375
static Type MakeGenericType (
378376
[DynamicallyAccessedMembers (Constructors)]
379377
Type type,
380378
Type [] arguments) =>
379+
// FIXME: https://github.com/xamarin/java.interop/issues/1192
380+
#pragma warning disable IL3050
381381
type.MakeGenericType (arguments);
382+
#pragma warning restore IL3050
382383

383384
Type[] arguments = type.GetGenericArguments ();
384385
if (arguments.Length == 0)
@@ -657,11 +658,12 @@ static JniValueMarshaler GetObjectArrayMarshaler (Type elementType)
657658
{
658659
const string makeGenericMethodMessage = "This code path is not used in Android projects.";
659660

660-
// FIXME: https://github.com/xamarin/java.interop/issues/1192
661661
[UnconditionalSuppressMessage ("Trimming", "IL2060", Justification = makeGenericMethodMessage)]
662-
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = makeGenericMethodMessage)]
663662
static MethodInfo MakeGenericMethod (MethodInfo method, Type type) =>
663+
// FIXME: https://github.com/xamarin/java.interop/issues/1192
664+
#pragma warning disable IL3050
664665
method.MakeGenericMethod (type);
666+
#pragma warning restore IL3050
665667

666668
Func<JniValueMarshaler> indirect = GetObjectArrayMarshalerHelper<object>;
667669
var reifiedMethodInfo = MakeGenericMethod (

0 commit comments

Comments
 (0)