Published on · Guide
.NET trimming and reflection: preserve behavior first
Trimming is a deployment optimization. Reflection dependencies and preservation annotations belong in protection regression tests.
Removal is not automatically protection
Microsoft's trimming guidance covers library compatibility and dynamic access. Removing unused code reduces shipped content; removing runtime-required code breaks functionality. Treat plugin modules, reflection-created types and serialization entry points carefully.
Test every preservation point
Map dynamic entry points to preservation reasons and tests. Validate plugin discovery, configuration reading and old-data migration, not only launch. Name-changing protection needs tests for name-based access. Trimming alone should not be described as concealing the core algorithm.
Your checklist
- Inventory dynamic entry points.
- Retain reproducible failure samples.
- Test compatibility with older data.
Primary sources
- Microsoft: Prepare libraries for trimming · Checked 2026-10-12