.NET MAUI › Performance & Optimization
How does the linker/trimming affect MAUI apps and how do you keep it safe?
IntermediateAnswer
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.