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 UnoAppWinUI solution template (App.cs). When the Frame cannot load the requested SourcePageType, the handler wraps the inner exception in InvalidOperationException and re-throws, crashing the app. Standard Uno/WinUI fail-fast template behavior for surfacing navigation problems in development.

Source

Thrown at src/SolutionTemplate/UnoAppWinUI/UnoAppWinUI/App.cs:95

			{
				// 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 the application state and stop any background activity
		deferral.Complete();
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Look at e.Exception for the real cause; the message's page name is just context.
  2. Confirm the page type exists, compiles, and that x:Class matches namespace.type.
  3. Debug the page constructor and OnNavigatedTo to capture the original exception first-chance.
  4. Replace the throw with logging + e.Handled=true + a fallback page for production tolerance.

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: {Page}", e.SourcePageType?.FullName);
    e.Handled = true;
}
Defensive patterns

Strategy: try-catch

Validate before calling

static bool CanNavigate(Frame f, Type page) => page != null && f.Content?.GetType() != page;

Try / catch

try { frame.Navigate(pageType); } catch (InvalidOperationException) { log.Error($"WinUI nav failed: {pageType}"); frame.Navigate(typeof(ErrorPage)); }

Prevention

When it happens

Trigger: Frame.Navigate to a page type that cannot be activated, or whose constructor/XAML initialization throws on the running WinUI target.

Common situations: Page not in the project, x:Class mismatch, constructor throws (null DI dependency, unresolved resource), or a platform guard excluding the page.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/b2ffdd5a85272d41. Report an issue: GitHub.