Skip to content

illink: TypeMapAssociation attribute always trimmed if there's a TypeMap attribute for the same type. #127004

Closed

Description

@rolfbjarne

Test case:

[assembly: TypeMap<UsedExternalTypeMap>("BothInExternalAndProxy", typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxy))]
[assembly: TypeMapAssociation<UsedExternalTypeMap>(typeof(BothInExternalAndProxy), typeof(BothInExternalAndProxyTarget))]

class BothInExternalAndProxy;
class BothInExternalAndProxyTarget;

Console.WriteLine(new BothInExternalAndProxy());

results in the TypeMapAssociation attribute being trimmed away.

This happens because when illink sees a TypeMap attribute, it marks the target type as instantiated:

_context.Annotations.MarkInstantiated(targetTypeDef);

which causes MarkRequirementsForInstantiatedTypes to exit early:

protected virtual void MarkRequirementsForInstantiatedTypes(TypeDefinition type)
{
if (Annotations.IsInstantiated(type))
return;

and then TypeMapHandler.ProcessInstantiatedType later in the method isn't called:

_typeMapHandler.ProcessInstantiated(type);

so then the TypeMapAssociation attribute is never marked.

Activity

  1. transferred this issue fromdotnet/dotneton Apr 16, 2026
  2. added
    untriaged
    on Apr 16, 2026
  3. added
    area-Tools-ILLink
    on Apr 16, 2026
  4. dotnet-policy-service commented on Apr 16, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/illink
    See info in area-owners.md if you want to be subscribed.

  5. added a commit that references this issue on Apr 16, 2026
    2ebb788
  6. rolfbjarne commented on Apr 20, 2026

    @rolfbjarne
    MemberAuthor

    CC @simonrozsival in case you run into this too with Android

  7. added a commit that references this issue on May 5, 2026
    e6a90cc
  8. removed
    untriaged
    on May 5, 2026
  9. locked and limited conversation to collaborators on Jun 5, 2026
  10. added a commit that references this issue on Jul 15, 2026
    510c6c7
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

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions