PrismLibrary/Prism · critical · AggregateException

One or more errors were encountered while executing the…

Error message

One or more errors were encountered while executing the OnInitialized Delegates

What it means

When two or more OnInitialized delegates throw during Prism startup, Prism aggregates them into an AggregateException with this message. Multiple registered startup callbacks failed in the same initialization pass.

Solutions

  1. Enumerate the AggregateException.InnerExceptions to see every delegate failure.
  2. Fix the shared root cause if all failures trace to one missing service or bad config value.
  3. Fix each delegate individually; add defensive checks around optional startup work.
  4. Add logging inside each delegate to attribute failures to specific lambdas.

Example fix

// before: two delegates both resolve an unregistered IConfig
.OnInitialized(c => c.Resolve<IConfig>().Load())
.OnInitialized(c => c.Resolve<IConfig>().Validate())
// after: register it
containerRegistry.RegisterSingleton<IConfig, AppConfig>();
Defensive patterns

Strategy: try-catch

Validate before calling

foreach (var dep in requiredStartupServices)
    if (!container.IsRegistered(dep)) throw new InvalidOperationException($"{dep.Name} missing");

Try / catch

try
{
    RunStartupDelegates();
}
catch (AggregateException ex)
{
    foreach (var inner in ex.InnerExceptions)
        logger.LogError(inner, "Startup delegate failure");
}

Prevention

When it happens

Trigger: Several OnInitialized lambdas registered on PrismAppBuilder each throwing — e.g. two independent startup initializers both hitting missing registrations or throwing configuration code.

Common situations: Refactors leaving several startup delegates broken; a shared dependency failure causing every delegate that resolves it to throw; environment misconfiguration affecting multiple initializers.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/b9e5a8e584e1be2b. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/PrismAppBuilder.cs:256

        {
            try
            {
                action(_container);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error executing Initialization Delegate.");
                errors.Add(ex);
            }
        });

        if (errors.Count == 1)
        {
            throw new PrismInitializationException("An error was encountered while invoking the OnInitialized Delegates", errors[0]);
        }
        else if (errors.Count > 1)
        {
            throw new AggregateException("One or more errors were encountered while executing the OnInitialized Delegates", [.. errors]);
        }

        var navRegistry = _container.Resolve<INavigationRegistry>();
        if (!navRegistry.IsRegistered(nameof(NavigationPage)))
        {
            var registry = _container as IContainerRegistry;
            registry
                .Register<PrismNavigationPage>(() => new PrismNavigationPage())
                .RegisterInstance(new ViewRegistration
                {
                    Name = nameof(NavigationPage),
                    View = typeof(PrismNavigationPage),
                    Type = ViewType.Page
                });
        }

        if (!navRegistry.IsRegistered(nameof(TabbedPage)))
        {

View on GitHub (pinned to 358118cd64)