Skip to content

Conversation

@jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Nov 3, 2021

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.

@jonathanpeppers jonathanpeppers force-pushed the typeregistrations-illink-warning branch from 15a881d to 8a5a548 Compare November 3, 2021 21:19
@jonathanpeppers jonathanpeppers marked this pull request as draft November 3, 2021 21:28
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`.
@jonathanpeppers jonathanpeppers force-pushed the typeregistrations-illink-warning branch from 8a5a548 to 9fe3b82 Compare November 3, 2021 21:38
@jonathanpeppers jonathanpeppers marked this pull request as ready for review November 3, 2021 22:03
@jonpryor jonpryor merged commit 13be0dd into dotnet:main Nov 4, 2021
@jonathanpeppers jonathanpeppers deleted the typeregistrations-illink-warning branch November 4, 2021 13:22
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants