unoplatform/uno · error · InvalidOperationException
Failed to load {e.SourcePageType.FullName}: {e.Exception}
Error message
Failed to load {e.SourcePageType.FullName}: {e.Exception} What it means
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.
Source
Thrown at src/SolutionTemplate/MyAppXamlTrim/MyAppXamlTrim.Shared/App.xaml.cs:100
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), args.Arguments);
}
// Ensure the current window is active
MainWindow.Activate();
}
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
/// <summary>
/// Configures global Uno Platform loggingView on GitHub (pinned to 0418340488)
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.
Example fix
// before
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
}
// after
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
_logger.LogError(e.Exception, "Nav failed (trim?): {Page}", e.SourcePageType?.FullName);
e.Handled = true;
} Defensive patterns
Strategy: try-catch
Validate before calling
// trim-specific: ensure the type is present in the trimmed binary static bool TypePresent(Type t) => t != null && t.GetConstructor(Type.EmptyTypes) != null;
Try / catch
try { frame.Navigate(pageType); } catch (InvalidOperationException ex) { log.Error(ex, $"Nav failed (trim?): {pageType}"); frame.Navigate(typeof(ErrorPage)); } Prevention
- 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.
When it happens
Trigger: Frame.Navigate to a page that was trimmed away, whose constructor/member was trimmed, or that throws during initialization under the trimmed binary.
Common situations: 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.
Related errors
- Failed to load {e.SourcePageType.FullName}: {e.Exception}
- Failed to load {e.SourcePageType.FullName}: {e.Exception}
- Failed to load {e.SourcePageType.FullName}: {e.Exception}
- Failed to load {e.SourcePageType.FullName}: {e.Exception}
- Failed to load {e.SourcePageType.FullName}: {e.Exception}
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/f8ccad9660ebcb98.
Report an issue: GitHub.