{"record":{"id":"b9e5a8e584e1be2b","repo":"PrismLibrary/Prism","slug":"one-or-more-errors-were-encountered-while-executing-the","errorCode":null,"errorMessage":"One or more errors were encountered while executing the OnInitialized Delegates","messagePattern":"One or more errors were encountered while executing the OnInitialized Delegates","errorType":"exception","errorClass":"AggregateException","httpStatus":null,"severity":"critical","filePath":"src/Maui/Prism.Maui/PrismAppBuilder.cs","lineNumber":256,"sourceCode":"        {\n            try\n            {\n                action(_container);\n            }\n            catch (Exception ex)\n            {\n                logger.LogError(ex, \"Error executing Initialization Delegate.\");\n                errors.Add(ex);\n            }\n        });\n\n        if (errors.Count == 1)\n        {\n            throw new PrismInitializationException(\"An error was encountered while invoking the OnInitialized Delegates\", errors[0]);\n        }\n        else if (errors.Count > 1)\n        {\n            throw new AggregateException(\"One or more errors were encountered while executing the OnInitialized Delegates\", [.. errors]);\n        }\n\n        var navRegistry = _container.Resolve<INavigationRegistry>();\n        if (!navRegistry.IsRegistered(nameof(NavigationPage)))\n        {\n            var registry = _container as IContainerRegistry;\n            registry\n                .Register<PrismNavigationPage>(() => new PrismNavigationPage())\n                .RegisterInstance(new ViewRegistration\n                {\n                    Name = nameof(NavigationPage),\n                    View = typeof(PrismNavigationPage),\n                    Type = ViewType.Page\n                });\n        }\n\n        if (!navRegistry.IsRegistered(nameof(TabbedPage)))\n        {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/PrismAppBuilder.cs#L238-L274","documentation":"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.","triggerScenarios":"Several OnInitialized lambdas registered on PrismAppBuilder each throwing — e.g. two independent startup initializers both hitting missing registrations or throwing configuration code.","commonSituations":"Refactors leaving several startup delegates broken; a shared dependency failure causing every delegate that resolves it to throw; environment misconfiguration affecting multiple initializers.","solutions":["Enumerate the AggregateException.InnerExceptions to see every delegate failure.","Fix the shared root cause if all failures trace to one missing service or bad config value.","Fix each delegate individually; add defensive checks around optional startup work.","Add logging inside each delegate to attribute failures to specific lambdas."],"exampleFix":"// before: two delegates both resolve an unregistered IConfig\n.OnInitialized(c => c.Resolve<IConfig>().Load())\n.OnInitialized(c => c.Resolve<IConfig>().Validate())\n// after: register it\ncontainerRegistry.RegisterSingleton<IConfig, AppConfig>();","handlingStrategy":"try-catch","validationCode":"foreach (var dep in requiredStartupServices)\n    if (!container.IsRegistered(dep)) throw new InvalidOperationException($\"{dep.Name} missing\");","typeGuard":null,"tryCatchPattern":"try\n{\n    RunStartupDelegates();\n}\ncatch (AggregateException ex)\n{\n    foreach (var inner in ex.InnerExceptions)\n        logger.LogError(inner, \"Startup delegate failure\");\n}","preventionTips":["Share a common try/catch/logging wrapper across startup delegates.","Register dependencies all startup delegates rely on before delegates run.","Bisect delegates when multiple failures appear to isolate regressions."],"tags":["dotnet","maui","prism","startup","aggregate"],"backgroundTag":"module-init-failed","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}