ILLinker Trimming Configuration Missing Constraint for Generic Type Reflection Metadata
0 reputation · 03 Jul 2020, 19:33 UTC
The goal is to retain reflection metadata for generic types when using ILLinker trimming with PublishTrimmed=true in .NET 5+ SDKs. The default trimming configuration does not include a rule to preserve System.Reflection.MetadataLoadContext and related generic type metadata, which can cause MissingMethodException or InvalidProgramException at runtime. Developers face an unresolved decision about whether to add a custom trimming descriptor XML file or apply [Preserve] attributes to generic type definitions, balancing size benefits against metadata completeness.
Should a custom trimming descriptor be preferred over [Preserve] attributes for preserving generic type metadata? What level of metadata preservation offers an acceptable trade‑off between binary size and runtime reliability? How can teams verify that the chosen approach does not introduce linker warnings or break trimmed builds?