{"record":{"id":"75ef8e43be226d25","repo":"dotnet/maui","slug":"you-must-invoke-loadapplication-before-calling","errorCode":null,"errorMessage":"You MUST invoke LoadApplication () before calling base.FinishedLaunching ()","messagePattern":"You MUST invoke LoadApplication \\(\\) before calling base\\.FinishedLaunching \\(\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs","lineNumber":48,"sourceCode":"\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;\n\t\t\t_application.SendResume();\n\t\t}\n\n\t\tpublic override void DidResignActive(Foundation.NSNotification notification)\n\t\t{","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs#L30-L66","documentation":"DidFinishLaunching calls SetMainPage and _application.SendStart(), which require _application to have been set by LoadApplication. If _application is still null when DidFinishLaunching runs, LoadApplication was never called (or was called after base.FinishedLaunching). The host enforces the ordering: LoadApplication first, then the launching callback.","triggerScenarios":"Overriding DidFinishLaunching and calling base.DidFinishLaunching before LoadApplication(application). Or not calling LoadApplication at all in the delegate.","commonSituations":"Custom AppDelegate that reordered startup calls. Template where LoadApplication was accidentally removed or commented out. Calling base.FinishedLaunching() first then LoadApplication().","solutions":["Call LoadApplication(app) inside DidFinishLaunching before invoking base.DidFinishLaunching(notification).","Confirm LoadApplication is present exactly once and not skipped on any startup path.","Follow the standard template order: LoadApplication(app); base.DidFinishLaunching(notification);"],"exampleFix":"// before\npublic override void DidFinishLaunching(NSNotification n)\n{\n    base.DidFinishLaunching(n); // _application null -> throws\n    LoadApplication(new App());\n}\n\n// after\npublic override void DidFinishLaunching(NSNotification n)\n{\n    LoadApplication(new App());\n    base.DidFinishLaunching(n);\n}","handlingStrategy":"validation","validationCode":"// Order: LoadApplication before base.DidFinishLaunching\npublic override void DidFinishLaunching(NSNotification n)\n{\n    LoadApplication(new App());\n    base.DidFinishLaunching(n);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call LoadApplication before base.DidFinishLaunching.","Keep startup ordering consistent with the project template.","Never reorder these calls during refactoring without testing."],"tags":["macos","startup","lifecycle","ordering","forms","maui"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}