{"record":{"id":"c6968087a43e6439","repo":"dotnet/maui","slug":"please-provide-a-main-window-in-your-app","errorCode":null,"errorMessage":"Please provide a main window in your app","messagePattern":"Please provide a main window in your app","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs","lineNumber":43,"sourceCode":"\n\t\tprotected void LoadApplication(Application application)\n\t\t{\n\t\t\tif (application == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(application));\n\n\t\t\tApplication.SetCurrentApplication(application);\n\t\t\t_application = application;\n\n\t\t\tif (NSApplication.SharedApplication.MainMenu != null)\n\t\t\t\t_storyboardMainMenuCount = (int)NSApplication.SharedApplication.MainMenu.Count;\n\n\t\t\tapplication.PropertyChanged += ApplicationOnPropertyChanged;\n\t\t}\n\n\t\tpublic override void DidFinishLaunching(Foundation.NSNotification notification)\n\t\t{\n\t\t\tif (MainWindow == null)\n\t\t\t\tthrow new InvalidOperationException(\"Please provide a main window in your app\");\n\n\t\t\tMainWindow.Display();\n\t\t\tMainWindow.MakeKeyAndOrderFront(NSApplication.SharedApplication);\n\t\t\tif (_application == null)\n\t\t\t\tthrow new InvalidOperationException(\"You MUST invoke LoadApplication () before calling base.FinishedLaunching ()\");\n\n\t\t\tSetMainPage();\n\t\t\tUpdateMainMenu();\n\t\t\t_application.SendStart();\n\t\t}\n\n\t\tpublic override void DidBecomeActive(Foundation.NSNotification notification)\n\t\t{\n\t\t\t// applicationDidBecomeActive\n\t\t\t// execute any OpenGL ES drawing calls\n\t\t\tif (_application == null || !_isSuspended)\n\t\t\t\treturn;\n\t\t\t_isSuspended = false;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs#L25-L61","documentation":"In DidFinishLaunching the host requires a non-null MainWindow before it can Display() and make it key. On macOS the main window normally comes from the storyboard/MainWindow.xib; if it is null the app has nothing to render into and throws InvalidOperationException. This is a host-configuration requirement, not an application-logic error.","triggerScenarios":"DidFinishLaunching runs with MainWindow == null. Happens when the storyboard lacks a main window, the window outlet is not connected, or a code-built app forgot to assign MainWindow before the launching callback.","commonSituations":"New macOS project missing the default MainWindow.storyboard wiring. Storyboard outlet for the window deleted/disconnected. Headless/test invocation of the delegate without a window.","solutions":["Ensure the app delegate's MainWindow outlet is connected to a window in the main storyboard, or assign it in code before DidFinishLaunching.","If building the window in code, construct and assign MainWindow in the delegate constructor or WillFinishLaunching.","Verify the storyboard's initial view controller is a window controller and the outlet is bound."],"exampleFix":"// before (code-built, window never set)\npublic override void DidFinishLaunching(NSNotification n)\n{\n    // MainWindow is null -> throws\n    base.DidFinishLaunching(n);\n}\n\n// after\npublic override void DidFinishLaunching(NSNotification n)\n{\n    MainWindow = new NSWindow(...);\n    base.DidFinishLaunching(n);\n}","handlingStrategy":"validation","validationCode":"if (MainWindow == null)\n    throw new InvalidOperationException(\"Configure MainWindow before launch\");\nbase.DidFinishLaunching(notification);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm the storyboard's main window outlet is connected.","For code-built apps, assign MainWindow before DidFinishLaunching.","Test the launch path in a clean build."],"tags":["macos","window","startup","storyboard","lifecycle","maui"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}