Rule 7 of 8 · Chapter III — Publish & Run
Publish Release with trimming — then test every reflection path.
Why this rule exists
The IL trimmer removes what it cannot prove is used. System.Text.Json with reflection, dynamic Activator calls, and third-party mappers are exactly the code it cannot prove — and they fail at runtime, in prod, with cryptic MissingMethodExceptions.
In practice
Keep a smoke checklist of reflection-heavy flows (serialization round-trips, dynamic component rendering) and run it against the published output, not dotnet run. Prefer source generators for JSON.
Sources
- Microsoft Learn — Trim self-contained deployments — Trimmer behavior and opt-outs