Back to results for “Startup”
.NET MAUI › Troubleshooting & Common Errors

Why does my app crash on startup only in Release builds?

Beginner

Answer

Release enables trimming/AOT, which can strip types used via reflection (JSON models, DI by reflection, XAML resolved dynamically). Fix by using source generators, [DynamicDependency]/[DynamicallyAccessedMembers], TrimmerRootAssembly, or disabling trimming for the assembly. Reproduce with a Release build and read the native crash log.
<ItemGroup>
    <TrimmerRootAssembly Include="MyApp.Models" />
</ItemGroup>
Real-world example A Release-only crash deserializing a model is fixed by rooting the models assembly so trimming keeps its members.

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