Skip to content

Handling TypeForwardedFromAttribute while trimmingΒ #1838

@eerhardt

Description

@eerhardt

The TypeForwardedFromAttribute allows for serializers (i.e. BinaryFormatter and XmlSerializer) to write Type names using a "stable" assembly name - one that won't change from version-to-version even if the Type moves assemblies.

These attributes typically point to facade assemblies.

The issue is that trimming will remove the facade assemblies. Thus code in XmlSerializer, which tries loading that assembly, is going to fail.

If the trimmer sees a TypeForwardedFromAttribute to a facade assembly, it is going to need to preserve that facade assembly after trimming.

I tried to find other attributes that have this same issue, and came up with 2 other instances of attributes taking assembly names:

  1. InternalsVisibleToAttribute
  2. DynamicDependencyAttribute

We may need to handle DynamicDependency similar to TypeForwardedFrom - if the attribute is referencing an assembly, that assembly can't be trimmed. My initial thoughts for InternalsVisibleTo is that it shouldn't matter if the assembly is trimmed.

If this pattern exists for more places than these attributes, we may have to add a new annotation that tells the trimmer the string is an "assembly name". Similarly to how [DynamicallyAccessedMembersAttribute] on a string tells the trimmer the string is a Type name.

cc @ericstj @safern

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions