Skip to content

Commit 13be0dd

Browse files
[generator] emit UnconditionalSuppressMessage in __TypeRegistrations (#908)
Building a .NET MAUI app with `-p:SuppressTrimAnalysisWarnings=false -p:TrimmerSingleWarn=false` shows the warning: src\Compatibility\Android.FormsViewGroup\src\obj\Release\net6.0-android\generated\src\Java.Interop.__TypeRegistrations.cs(35,4): error IL2057: Java.Interop.__TypeRegistrations.Lookup(String[],String): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type. This code path should not even be used normally. It is only called when running inside the Android Designer. For now, let's simply emit an extra attribute to ignore the warning: [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2057")] This attribute was added in .NET 5, so we can always emit the code and use `#if NET5_0_OR_GREATER`.
1 parent e56a8c8 commit 13be0dd

File tree

22 files changed

+66
-0
lines changed

22 files changed

+66
-0
lines changed

tests/generator-Tests/expected.ji/Adapters/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/Android.Graphics.Color/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/Arrays/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/Constructors/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/InterfaceMethodsConflict/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/NestedTypes/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/NonStaticFields/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/NormalMethods/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/NormalProperties/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

tests/generator-Tests/expected.ji/ParameterXPath/Java.Interop.__TypeRegistrations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void RegisterPackages ()
2323
#endif // def MONODROID_TIMING
2424
}
2525

26+
#if NET5_0_OR_GREATER
27+
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage ("Trimming", "IL2057")]
28+
#endif
2629
static Type Lookup (string[] mappings, string javaType)
2730
{
2831
var managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);

0 commit comments

Comments
 (0)