Skip to content

Add support for DisableRuntimeMarshallingAttribute #15684

Open

Description

@rolfbjarne

The runtime is adding an assembly-level DisableRuntimeMarshallingAttribute, which does a few things:

  • Consider all unmanaged types as blittable.
  • Disables support for runtime marshalling.

If all assemblies (with P/Invokes) have this attribute, then we don't need to include support for runtime marshalling into an app. Mono has removed this support into a component (dotnet/runtime#61685), which means that it should be fairly easy to shrink apps a bit by:

  • Automatically detect whether all assemblies with P/Invokes have this attribute.
  • Disable the inclusion of the runtime marshalling component.

A prerequisite would be to fix our platform assembly (Microsoft.iOS.dll, etc) to have the DisableRuntimeMarshalling attribute, which would need either:

a) Enable source-generated DllImports, or
b) Fix all our P/invokes to only use blittable types.

The solution forward is probably to do a) first, and then check each dll import the source-generator modified to see if we can modify the DllImport to use blittable types only (since I suspect most DllImports aren't blittable by accident, and can easily be made blittable to avoid the source generator add unnecessary code).

Note that b) would likely require us to write a (cecil) test to ensure that all P/Invokes only use blittable types, because we can't rely on the compiler (dotnet/roslyn#64086).

Ref: #15668


We've fixed all our P/Invokes to only use blittable types, but the task we want to use to detect if an assembly requires the marshal-ilgen component or not has several bugs, which we're now blocked on:

Activity

  1. added
    enhancement
    dotnet
    on Aug 16, 2022
  2. added this to the .NET 8 milestone on Aug 16, 2022
  3. modified the milestones: .NET 8, .NET 9 on Sep 20, 2023
  4. 173 remaining items

  5. modified the milestones: .NET 9, .NET 10 on Sep 27, 2024
  6. added
    dotnet-external-dependency
    on Feb 27, 2025
  7. removed their assignment
    on Jun 20, 2025
  8. rolfbjarne commented on Sep 9, 2025

    @rolfbjarne
    MemberAuthor

    We won't be able to do this, because we depend on runtime fixes that won't happen: dotnet/runtime#112982 (comment).

  9. rolfbjarne commented on Oct 28, 2026

    @rolfbjarne
    MemberAuthor

    Reopening; we're not using Mono anymore, so maybe we can do this after all.

  10. modified the milestones: .NET 10, .NET 12 on Oct 28, 2026
  11. removed
    dotnet-external-dependency
    on Oct 28, 2026
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

    dotnetenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions