How does the linker/trimming affect MAUI apps and how do you keep it safe?
Short answer
Trimming removes unused IL to shrink the app, but reflection-based code can be trimmed away, causing runtime failures.
Advertisement
AModel answer
Trimming removes unused IL to shrink the app, but reflection-based code can be trimmed away, causing runtime failures. Use trim-safe patterns (source generators, DynamicDependency attributes), mark types with [DynamicallyAccessedMembers], or configure a trimmer XML/feature switches to preserve needed members. Test Release builds thoroughly.
<ItemGroup>
<TrimmerRootAssembly Include="MyApp.Models" />
</ItemGroup>Real-world example
A crash that only appeared in Release traced to a trimmed model type used via reflection; rooting the assembly fixed it.
Likely follow-ups
- Why do Release-only crashes happen? | How do you preserve reflected types?
Related topics