Skip to content

[One .NET] fix remaining Mono.Android.Export linker warning - #6216

Merged
jonpryor merged 1 commit into
dotnet:mainfrom
jonathanpeppers:dotnet-remove-dynamicdependency
Sep 3, 2021
Merged

jonpryor merged 1 commit into
dotnet:mainfrom
jonathanpeppers:dotnet-remove-dynamicdependency

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Aug 20, 2021 •

Copy link
Copy Markdown
Member

Context: #5652

If you build an app with:

> dotnet build -c Release -p:SuppressTrimAnalysisWarnings=false

You get the linker warning:

src\Mono.Android\Android.Runtime\AndroidRuntime.cs(296,5): warning IL2026: Android.Runtime.AndroidTypeManager.CreateDynamicCallback(MethodInfo): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.

We can simply suppress the warning:

[UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "DynamicDependency should preserve the Create() method.")]

If we applied this, every app would preserve
Mono.Android.Export.dll, so we should not do this:

[DynamicDependency ("Create", "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

This is already preserved because we have a DynamicDependency in
ExportAttribute.cs:

[DynamicDependency (DynamicallyAccessedMemberTypes.All, "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

I also had to bring in the source for UnconditionalSuppressMessage
for monoandroid10 or netstandard2.0 assemblies. I also changed an
MSBuild Condition, so it will continue to work in .NET 7.

@jonathanpeppers
jonathanpeppers force-pushed the dotnet-remove-dynamicdependency branch from 941f4a6 to a957180 Compare August 27, 2021 20:56
@jonathanpeppers jonathanpeppers changed the title [One .NET] remove in-tree DynamicDependencyAttribute [One .NET] fix remaining Mono.Android.Export linker warning Aug 27, 2021
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review August 31, 2021 14:00
@@ -0,0 +1,92 @@
// Licensed to the .NET Foundation under one or more agreements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this file was copied from elsewhere -- which I think it was -- then it should instead be in e.g. src-ThirdParty/….

This was overlooked with DynamicallyAccessedMemberTypes.cs and DynamicDependencyAttribute.cs, so those should likewise move. :-(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be moved around now.

Context: dotnet#5652

If you build an app with:

    > dotnet build -c Release -p:SuppressTrimAnalysisWarnings=false

You get the linker warning:

    src\Mono.Android\Android.Runtime\AndroidRuntime.cs(296,5): warning IL2026: Android.Runtime.AndroidTypeManager.CreateDynamicCallback(MethodInfo): Using method 'System.Reflection.Assembly.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.

We can simply suppress the warning:

    [UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "DynamicDependency should preserve the Create() method.")]

If we applied this, every app would preserve
`Mono.Android.Export.dll`, so we should not do this:

    [DynamicDependency ("Create", "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

This is already preserved because we have a `DynamicDependency` in
`ExportAttribute.cs`:

    [DynamicDependency (DynamicallyAccessedMemberTypes.All, "Java.Interop.DynamicCallbackCodeGenerator", "Mono.Android.Export")]

I also had to bring in the source for `UnconditionalSuppressMessage`
for `monoandroid10` or `netstandard2.0` assemblies. I also changed an
MSBuild `Condition`, so it will continue to work in .NET 7.
@jonathanpeppers
jonathanpeppers force-pushed the dotnet-remove-dynamicdependency branch from a957180 to d09d391 Compare September 2, 2021 19:51
@jonpryor
jonpryor merged commit 8eb10dd into dotnet:main Sep 3, 2021
@jonathanpeppers
jonathanpeppers deleted the dotnet-remove-dynamicdependency branch September 3, 2021 02:07
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 24, 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