{"record":{"id":"227d9c5eba5cef77","repo":"PrismLibrary/Prism","slug":"you-must-call-createwindow-on-the-prismappbuilder","errorCode":null,"errorMessage":"You must call CreateWindow on the PrismAppBuilder.","messagePattern":"You must call CreateWindow on the PrismAppBuilder\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"critical","filePath":"src/Maui/Prism.Maui/PrismAppBuilder.cs","lineNumber":283,"sourceCode":"                .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        {\n            var registry = _container as IContainerRegistry;\n            registry.RegisterForNavigation<TabbedPage>();\n        }\n    }\n\n    internal void OnCreateWindow()\n    {\n        if (_createWindow is null)\n            throw new ArgumentException(\"You must call CreateWindow on the PrismAppBuilder.\");\n\n        // Ensure that this is executed before we navigate.\n        OnInitialized();\n        var onStart = _createWindow(_container, _container.Resolve<INavigationService>());\n        onStart.Wait();\n    }\n\n    /// <summary>\n    /// When the <see cref=\"Application\"/> is started and the native platform calls <see cref=\"IApplication.CreateWindow(IActivationState?)\"/>\n    /// this delegate will be invoked to do your initial Navigation.\n    /// </summary>\n    /// <param name=\"createWindow\">The Navigation Delegate.</param>\n    /// <returns>The <see cref=\"PrismAppBuilder\"/>.</returns>\n    public PrismAppBuilder CreateWindow(Func<IContainerProvider, INavigationService, Task> createWindow)\n    {\n        _createWindow = createWindow;\n        return this;\n    }","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/PrismAppBuilder.cs#L265-L301","documentation":"PrismAppBuilder.OnCreateWindow requires that a CreateWindow delegate was configured on the builder. If none was supplied, it throws this ArgumentException because Prism cannot determine which page to show when the MAUI platform asks for the app's first window.","triggerScenarios":"Using UsePrism without chaining .CreateWindow(navigation => ...) (or CreateWindow returning null delegate) so _createWindow is null when MAUI creates the app window.","commonSituations":"New project setup missing the CreateWindow call; copying an App builder from a template that sets the window elsewhere; accidentally deleting the CreateWindow line during refactoring.","solutions":["Add .CreateWindow(container => container.Resolve<INavigationService>().NavigateAsync(\"/ MainPage\")) (or equivalent) to your PrismAppBuilder chain in MauiProgram.CreateMauiApp.","Ensure you call CreateWindow on the builder returned by UsePrism, not somewhere unreachable.","Verify the navigation path passed to CreateWindow resolves to a registered page."],"exampleFix":"// before\nbuilder.UsePrism(prism => prism.RegisterTypes(r => r.ForNavigation<MainPage>()));\n// after\nbuilder.UsePrism(prism => prism\n    .RegisterTypes(r => r.ForNavigation<MainPage>())\n    .CreateWindow(nav => nav.CreateBuilder()\n        .AddSegment(\"MainPage\")\n        .NavigateAsync()));","handlingStrategy":"validation","validationCode":"// In MauiProgram, before building the app\nvar prism = builder.UsePrism(prism => ...);\n// ensure CreateWindow was chained\nif (!typeof(PrismAppBuilder).GetField(\"_createWindow\", BindingFlags.NonPublic | BindingFlags.Instance)!\n       .GetValue(prism)!.Equals(null))\n    throw new InvalidOperationException(\"CreateWindow not configured\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always chain .CreateWindow(...) when calling UsePrism in MauiProgram.","Start new projects from an up-to-date Prism.Maui template.","Code-review App/MauiProgram startup for the CreateWindow call before release."],"tags":["dotnet","maui","prism","startup","navigation"],"backgroundTag":"missing-required-argument","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"}