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 shipped in the Uno 5.3 solution template (uno53AppWithLib). The Frame raises NavigationFailed when it cannot instantiate or navigate to the requested SourcePageType; the template re-throws the inner exception wrapped with the page name as an InvalidOperationException, crashing the app. This is intentional fail-fast behavior so navigation problems surface immediately during development.

Source

Thrown at src/SolutionTemplate/5.3/uno53AppWithLib/uno53AppWithLib/App.xaml.cs:63

            // 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);
        }

        MainWindow.SetWindowIcon();
        // 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>
    /// Configures global Uno Platform logging
    /// </summary>
    public static void InitializeLogging()
    {
#if DEBUG
        // Logging is disabled by default for release builds, as it incurs a significant
        // initialization cost from Microsoft.Extensions.Logging setup. If startup performance
        // is a concern for your application, keep this disabled. If you're running on the web or
        // desktop targets, you can use URL or command line parameters to enable it.
        //
        // For more performance documentation: https://platform.uno/docs/articles/Uno-UI-Performance.html

        var factory = LoggerFactory.Create(builder =>
        {
#if __WASM__

View on GitHub (pinned to 0418340488)

Solutions

  1. Open the inner e.Exception to find the true root cause — the wrapper only adds the page name; the real error is inside.
  2. Verify the target page type is in the same assembly and its x:Class matches the namespace.type exactly.
  3. Step through the page's constructor / OnNavigatedTo to find what throws; check for null dependencies or unresolved resources.
  4. For production resilience, replace the throw with logging + a fallback page rather than crashing (see defense strategy).

Example fix

// before (template default — crashes the app)
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
    throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
}

// after (log + show fallback page)
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
    _logger.LogError(e.Exception, "Navigation to {Page} failed", e.SourcePageType?.FullName);
    e.Handled = true;
    (sender as Frame)?.Navigate(typeof(ErrorPage));
}
Defensive patterns

Strategy: try-catch

Validate before calling

static bool CanNavigate(Frame f, Type page) => page != null && f.Content?.GetType() != page; // lightweight pre-check; full safety needs try/catch

Try / catch

try { frame.Navigate(pageType); } catch (InvalidOperationException) { /* template re-throws on nav failure; wrap Navigate */ log.Error($"Navigation to {pageType} failed"); frame.Navigate(typeof(ErrorPage)); }

Prevention

When it happens

Trigger: Frame.Navigate(typeof(SomePage)) where SomePage's type is registered but its XAML/code-behind throws during construction, or the page type cannot be found/instantiated on the current platform.

Common situations: Page missing from the project, a x:Class mismatch, a constructor that throws (null reference, missing service/dependency), platform-conditional code that fails on a target, or navigation to a page whose XAML resource cannot resolve.

Related errors


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