{"record":{"id":"f8ccad9660ebcb98","repo":"unoplatform/uno","slug":"failed-to-load-e-sourcepagetype-fullname-e-exc-f8ccad","errorCode":null,"errorMessage":"Failed to load {e.SourcePageType.FullName}: {e.Exception}","messagePattern":"Failed to load (.+?): (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SolutionTemplate/MyAppXamlTrim/MyAppXamlTrim.Shared/App.xaml.cs","lineNumber":100,"sourceCode":"\t\t\t\t{\n\t\t\t\t\t// When the navigation stack isn't restored navigate to the first page,\n\t\t\t\t\t// configuring the new page by passing required information as a navigation\n\t\t\t\t\t// parameter\n\t\t\t\t\trootFrame.Navigate(typeof(MainPage), args.Arguments);\n\t\t\t\t}\n\t\t\t\t// Ensure the current window is active\n\t\t\t\tMainWindow.Activate();\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Invoked when Navigation to a certain page fails\n\t\t/// </summary>\n\t\t/// <param name=\"sender\">The Frame which failed navigation</param>\n\t\t/// <param name=\"e\">Details about the navigation failure</param>\n\t\tvoid OnNavigationFailed(object sender, NavigationFailedEventArgs e)\n\t\t{\n\t\t\tthrow new InvalidOperationException($\"Failed to load {e.SourcePageType.FullName}: {e.Exception}\");\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Invoked when application execution is being suspended.  Application state is saved\n\t\t/// without knowing whether the application will be terminated or resumed with the contents\n\t\t/// of memory still intact.\n\t\t/// </summary>\n\t\t/// <param name=\"sender\">The source of the suspend request.</param>\n\t\t/// <param name=\"e\">Details about the suspend request.</param>\n\t\tprivate void OnSuspending(object sender, SuspendingEventArgs e)\n\t\t{\n\t\t\tvar deferral = e.SuspendingOperation.GetDeferral();\n\t\t\t//TODO: Save application state and stop any background activity\n\t\t\tdeferral.Complete();\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Configures global Uno Platform logging","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SolutionTemplate/MyAppXamlTrim/MyAppXamlTrim.Shared/App.xaml.cs#L82-L118","documentation":"Default OnNavigationFailed handler in the MyAppXamlTrim solution template (XAML trimming scenario). The Frame raises NavigationFailed when a page cannot be instantiated; the template wraps the inner exception and re-throws as InvalidOperationException, crashing the app. In a trimming-aware app this commonly fires when trimming has removed a page type or its members.","triggerScenarios":"Frame.Navigate to a page that was trimmed away, whose constructor/member was trimmed, or that throws during initialization under the trimmed binary.","commonSituations":"XAML trimming/AOT removed the page type or a referenced type; missing DynamicDependency/DeserializeXaml roots; reflection-based activation failing; constructor throwing because a dependency was trimmed.","solutions":["Inspect e.Exception for the underlying failure (often TypeLoadException or MissingMethodException under trimming).","Add trim/AOT roots for the page and types it references (DynamicDependency attributes, rd.xml, or TrimmingRoots), or mark the page with a dynamic-availability attribute.","Verify the page type is still present in the trimmed binary with a linkage check.","For production resilience, log + set e.Handled=true and navigate to a fallback page instead of re-throwing."],"exampleFix":"// before\nvoid OnNavigationFailed(object sender, NavigationFailedEventArgs e)\n{\n    throw new InvalidOperationException($\"Failed to load {e.SourcePageType.FullName}: {e.Exception}\");\n}\n\n// after\nvoid OnNavigationFailed(object sender, NavigationFailedEventArgs e)\n{\n    _logger.LogError(e.Exception, \"Nav failed (trim?): {Page}\", e.SourcePageType?.FullName);\n    e.Handled = true;\n}","handlingStrategy":"try-catch","validationCode":"// trim-specific: ensure the type is present in the trimmed binary\nstatic bool TypePresent(Type t) => t != null && t.GetConstructor(Type.EmptyTypes) != null;","typeGuard":null,"tryCatchPattern":"try { frame.Navigate(pageType); } catch (InvalidOperationException ex) { log.Error(ex, $\"Nav failed (trim?): {pageType}\"); frame.Navigate(typeof(ErrorPage)); }","preventionTips":["Add trimming/AOT roots (DynamicDependency, rd.xml, TrimmingRoots) for navigable page types.","Run the trim-warning report and fix every IL2055/IL2027 touching pages.","Smoke-test navigation on a Release/trimmed build, not just Debug."],"tags":["navigation","uno-template","frame","trimming","aot","boilerplate"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}