{"record":{"id":"64ef0d7d6c84fa14","repo":"dotnet/maui","slug":"you-must-invoke-loadapplication-before-calling-64ef0d","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/iOS/FormsApplicationDelegate.cs","lineNumber":57,"sourceCode":"\t\t// now in background\n\t\tpublic override void DidEnterBackground(UIApplication uiApplication)\n\t\t{\n\t\t\t// applicationDidEnterBackground\n\t\t}\n\n\t\t// finish initialization before display to user\n\t\tpublic override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)\n\t\t{\n\t\t\t// check contents of launch options and evaluate why the app was launched and respond\n\t\t\t// initialize the important data structures\n\t\t\t// prepare you apps window and views for display\n\t\t\t// keep lightweight, anything long winded should be executed asynchronously on a secondary thread.\n\t\t\t// application:didFinishLaunchingWithOptions\n\t\t\tif (Window == null)\n\t\t\t\tWindow = new UIWindow(UIScreen.MainScreen.Bounds);\n\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\t_application.SendStart();\n\t\t\treturn true;\n\t\t}\n\n\t\t// about to become foreground, last minute preparatuin\n\t\tpublic override void OnActivated(UIApplication uiApplication)\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{\n\t\t\t\t_isSuspended = false;\n\t\t\t\tCultureInfo.CurrentCulture.ClearCachedData();\n\t\t\t\tTimeZoneInfo.ClearCachedData();\n\t\t\t\t_application.SendResume();\n\t\t\t}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/FormsApplicationDelegate.cs#L39-L75","documentation":"FormsApplicationDelegate.FinishedLaunching throws InvalidOperationException(\"You MUST invoke LoadApplication() before calling base.FinishedLaunching()\") when _application is null. The AppDelegate contract requires LoadApplication(Application) to be called in FinishedLaunching before the base, otherwise the platform has no Xamarin.Forms Application to display.","triggerScenarios":"Overriding FinishedLaunching in a custom AppDelegate and calling base.FinishedLaunching before (or without) calling LoadApplication(new App()); forgetting the LoadApplication call entirely.","commonSituations":"New iOS project scaffolding where the LoadApplication line was removed; refactoring FinishedLaunching and reordering base.Load; copy-paste from a non-Forms template.","solutions":["Call LoadApplication(new App()) inside FinishedLaunching before base.FinishedLaunching.","Verify the call order: LoadApplication first, then return base.FinishedLaunching(...).","Check the AppDelegate for accidental early returns."],"exampleFix":"// before\npublic override bool FinishedLaunching(UIApplication app, NSDictionary opts)\n    => base.FinishedLaunching(app, opts);\n// after\npublic override bool FinishedLaunching(UIApplication app, NSDictionary opts)\n{\n    LoadApplication(new App());\n    return base.FinishedLaunching(app, opts);\n}","handlingStrategy":"validation","validationCode":"// In FinishedLaunching:\nif (_application == null)\n    LoadApplication(new App());\nreturn base.FinishedLaunching(app, options);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call LoadApplication before base.FinishedLaunching.","Order: Forms.Init() -> LoadApplication() -> base.FinishedLaunching().","Scaffold iOS projects from the Forms template to avoid missing calls."],"tags":["maui","xamarin-forms","ios","appdelegate","lifecycle","startup","invalidoperation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}