Skip to content

Linking an empty .NET MAUI app produces inconsistent binaries #86242

Closed

Description

@filipnavara

Repro:

  • Create a MAUI app with dotnet new maui
  • Build it for MacCatalyst or iOS, eg. dotnet build -f net8.0-maccatalyst
  • Check the linked assemblies in obj/Debug/net8.0-maccatalyst/maccatalyst-x64/linked/.

Observations:

  • In Microsoft.Maui.Controls.dll the INavigation.PopToRootAsync() method is trimmed from the interface.
  • In Microsoft.Maui.Compatibility.dll the Microsoft.Maui.Controls.Compatibility.Platform.iOS.Platform type keeps an explicit implementation of the INavigation.PopToRootAsync() method.

Expectations:

  • Either the method is not trimmed from the interface, or all explicit implementations of the method are trimmed too.

Activity

  1. added
    area-Tools-ILLink
    on May 15, 2023
  2. ghost added
    untriaged
    on May 15, 2023
  3. sbomer commented on May 18, 2023

    @sbomer
    Member

    I was able to reproduce the issue with the repro that you shared with @vitek-karas. Here's what's happening:

    • The custom step ManagedRegistrarStep sets the assembly action for Microsoft.Maui.Controls.Compatibility.dll to save (it calls AppBundleRewriter.SaveCurrentAssembly). On its own, this might have been enough to repro the issue because the fix Mark .overrides from marked methods in a copy assembly #82197 doesn't take into account save assemblies - we should probably fix that.
    • On top of that, MarkStep never marks the Platform implementation of INavigation.PopToRootAsync, because of the custom data DisableMarkingOfCopyAssemblies:
      if (!Context.TryGetCustomData ("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
      So even if we fix the above, it doesn't help in this case.

    I don't have full context, but it seems like the action is set to save because the registrar is injecting UnmanagedCallersOnly trampoline methods for interop. Maybe we should change the behavior of DisableMarkingOfCopyAssemblies so that it doesn't also skip marking of save assemblies. @vitek-karas thoughts?

  4. filipnavara commented on May 18, 2023

    @filipnavara
    MemberAuthor

    Thanks for analyzing it!

    Before I reported the issue I made sure that it reproduces on stock runtime/linker/workloads. The repro I sent, however, used a new feature introduced in dotnet/macios#18268. In that case the ManagedRegistrarStep is an additional step that takes place in the linker pipeline. It does generate new code and as a consequence changes the action from Copy to Save. Unfortunately that opened a small can of worms, where the behavior of the Save action is sometimes unintuitive or broken.

    I suppose that on the stock workload the issue is the use of DisableMarkingOfCopyAssemblies you described. I'll try to selectively disable that and check the output.

  5. filipnavara commented on May 18, 2023

    @filipnavara
    MemberAuthor

    I suppose that on the stock workload the issue is the use of DisableMarkingOfCopyAssemblies you described. I'll try to selectively disable that and check the output.

    Removing DisableMarkingOfCopyAssemblies (by setting <MarkCopiedAssemblies>true</MarkCopiedAssemblies> in the .csproj file) seems to have solved the issue even for the case with ManagedRegistrarStep.

    I was not able reproduce the issue on stock workloads this time. I'm not sure if I accidentally changed something or if it's a result of Tuesday's updates (unlikely). I'll try again tomorrow.

  6. ghost added
    in-pr
    on May 19, 2023
  7. ghost removed
    in-pr
    on May 19, 2023
  8. ghost removed
    untriaged
    on May 19, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions