Skip to content

Remove the crossgen2 TypeRef workaround for trimmable-static type maps #26343

Description

@rolfbjarne

The trimmable-static registrar generates its type map assemblies (_<platform>.TypeMap.dll) with Mono.Cecil, so the types named by the type-map entries only appear as assembly-qualified name strings in the custom attribute blobs — the assembly has no TypeRef row for them.

That's valid metadata (ECMA-335 II.23.3 only requires the type to be stored as a SerString holding its canonical name, and neither the CustomAttribute (II.22.10) nor the TypeRef (II.22.38) validity rules require a matching TypeRef row), but crossgen2 assumes the row is there and crashes with a NotImplementedException in ModuleTokenResolver.GetModuleTokenForType when ReadyToRun-compiling the type map assembly.

Filed upstream as dotnet/runtime#131527.

Until that's fixed, TrimmableRegistrarStep.EmitTypeReferencesForTypeMaps works around it by emitting an unused <TypeReferences>.KeepTypeReferences () method that does ldtoken + pop for every externally defined type the maps name, which forces Cecil to emit the TypeRef rows. It's gated on CoreCLR + PublishReadyToRun, because that's the only configuration that needs it, and the extra metadata isn't free (it adds ~64 KB per runtime identifier to _Microsoft.macOS.TypeMap.dll).

Once dotnet/runtime#131527 is fixed and we've moved to a runtime that contains the fix, remove:

  • EmitTypeReferencesForTypeMaps and its call site in tools/dotnet-linker/Steps/TrimmableRegistrarStep.cs
  • and update the expected app sizes if any of them change.

Activity

  1. added this to the .NET 11 milestone on Jul 29, 2026
  2. added theissue type on Jul 29, 2026
  3. rolfbjarne commented on Aug 31, 2026

    @rolfbjarne
    MemberAuthor

    The runtime fix won't be in .NET 11 (the fix was reverted/modified, see dotnet/runtime#132811), but it should be in .NET 12.

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

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions