dotnet/maui · critical · InvalidOperationException
You MUST invoke LoadApplication () before calling base.Finis
Error message
You MUST invoke LoadApplication () before calling base.FinishedLaunching ()
What it means
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.
Source
Thrown at src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs:48
Application.SetCurrentApplication(application);
_application = application;
if (NSApplication.SharedApplication.MainMenu != null)
_storyboardMainMenuCount = (int)NSApplication.SharedApplication.MainMenu.Count;
application.PropertyChanged += ApplicationOnPropertyChanged;
}
public override void DidFinishLaunching(Foundation.NSNotification notification)
{
if (MainWindow == null)
throw new InvalidOperationException("Please provide a main window in your app");
MainWindow.Display();
MainWindow.MakeKeyAndOrderFront(NSApplication.SharedApplication);
if (_application == null)
throw new InvalidOperationException("You MUST invoke LoadApplication () before calling base.FinishedLaunching ()");
SetMainPage();
UpdateMainMenu();
_application.SendStart();
}
public override void DidBecomeActive(Foundation.NSNotification notification)
{
// applicationDidBecomeActive
// execute any OpenGL ES drawing calls
if (_application == null || !_isSuspended)
return;
_isSuspended = false;
_application.SendResume();
}
public override void DidResignActive(Foundation.NSNotification notification)
{View on GitHub (pinned to f377ff1c5e)
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);
Example fix
// before
public override void DidFinishLaunching(NSNotification n)
{
base.DidFinishLaunching(n); // _application null -> throws
LoadApplication(new App());
}
// after
public override void DidFinishLaunching(NSNotification n)
{
LoadApplication(new App());
base.DidFinishLaunching(n);
} Defensive patterns
Strategy: validation
Validate before calling
// Order: LoadApplication before base.DidFinishLaunching
public override void DidFinishLaunching(NSNotification n)
{
LoadApplication(new App());
base.DidFinishLaunching(n);
} Prevention
- Always call LoadApplication before base.DidFinishLaunching.
- Keep startup ordering consistent with the project template.
- Never reorder these calls during refactoring without testing.
When it happens
Trigger: Overriding DidFinishLaunching and calling base.DidFinishLaunching before LoadApplication(application). Or not calling LoadApplication at all in the delegate.
Common situations: Custom AppDelegate that reordered startup calls. Template where LoadApplication was accidentally removed or commented out. Calling base.FinishedLaunching() first then LoadApplication().
Related errors
- call Forms.Init() before this
- application
- Please provide a main window in your app
- NavigationPage must have a root Page before being used. Eith
- You MUST invoke LoadApplication () before calling base.Finis
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/75ef8e43be226d25.
Report an issue: GitHub.