Skip to content

marshal-ilgen component should be optional #7276

Closed as not planned
Closed as not planned

Description

@jonpryor

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 7

Description

With #7249 and #7260, the marshal-ilgen component is always included into Android apps.

For .NET 8 (?), we should try to make inclusion of this component optional, such that it is included only if required.

As a prerequisite, this will require:

  1. updating Mono.Androi.dll and Java.Interop.dll (and others?) to use the DllImport Generator.
  2. Updating the above assemblies to have [assembly:DisableRuntimeMarshallingAttribute]

Then, we'd need to update the App Build process to scan all included assemblies, and if all included assemblies contain [assembly:DisableRuntimeMarshallingAttribute], then the marshal-ilgen component can be removed from the .apk.

Activity

  1. added
    Area: App+Library BuildIssues when building Library projects or Application projects.
    needs-triageIssues that need to be assigned.
    on Aug 17, 2022
  2. added this to the .NET 8 milestone on Aug 17, 2022
  3. dellis1972 commented on Aug 18, 2022

    @dellis1972
    Contributor

    So is the plan for users to add this attribute to their own assemblies? I assume this will only need to check on assemblies which reference Mono.Android? or does it apply to every single assembly ?

  4. jonpryor commented on Aug 18, 2022

    @jonpryor
    ContributorAuthor

    @dellis1972 asked:

    is the plan for users to add this attribute to their own assemblies?

    My interpretation is that yes, any/every assembly which contains P/Invokes would need to opt-in to this new mechanism by adding [assembly:DisableRuntimeMarshallingAttribute]. This would not be restricted to just assemblies which reference Mono.Android.dll.

    Which possibly raises as many questions as that answers. How does one efficiently tell if an assembly contains no P/Invokes?

  5. added a commit that references this issue on Jul 9, 2024
  6. modified the milestones: .NET 9, .NET 10 on Aug 26, 2024
  7. added theissue type on Apr 3, 2025
  8. jonathanpeppers commented on Aug 7, 2026

    @jonathanpeppers
    Member

    Automated bot note: closing this issue as obsolete for .NET 11. .NET for Android supports CoreCLR in .NET 11, and the Mono marshal-ilgen component is not packaged in CoreCLR applications (it appears only in MonoVM APK baselines). Consequently, adding [DisableRuntimeMarshalling] to Mono.Android.dll or Java.Interop.dll would not provide the APK-size/component-removal benefit described by this issue for the supported runtime.

  9. locked and limited conversation to collaborators on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.enhancementProposed change to current functionality.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions