Skip to content

Commit 15a881d

Browse files
[generator] emit UnconditionalSuppressMessage in __TypeRegistrations
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 I used `#if NET5_0_OR_GREATER`. I think we can simply emit the attribute for the `net6.0` version of `generator.csproj`.
1 parent e56a8c8 commit 15a881d

File tree

1 file changed

+3
-0
lines changed
  • tools/generator/Java.Interop.Tools.Generator.ObjectModel

1 file changed

+3
-0
lines changed

tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ public static void GenerateTypeRegistrations (CodeGenerationOptions opt, Generat
208208
sw.WriteLine ("#endif // def MONODROID_TIMING");
209209
sw.WriteLine ("\t\t}");
210210
sw.WriteLine ();
211+
#if NET5_0_OR_GREATER
212+
sw.WriteLine("\t\t[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2057\")]");
213+
#endif
211214
sw.WriteLine ("\t\tstatic Type{0} Lookup (string[] mappings, string javaType)", opt.NullableOperator);
212215
sw.WriteLine ("\t\t{");
213216
sw.WriteLine ("\t\t\tvar managedType = Java.Interop.TypeManager.LookupTypeMapping (mappings, javaType);");

0 commit comments

Comments
 (0)