Back to results for “Performance”
.NET MAUI › Performance & Optimization

How does the linker/trimming affect MAUI apps and how do you keep it safe?

Intermediate

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.

Common follow-ups: Why do Release-only crashes happen? | How do you preserve reflected types?