dotnet/maui · error · ArgumentNullException
application
Error message
application
What it means
FormsApplicationDelegate.LoadApplication throws ArgumentNullException(nameof(application)) when called with null. LoadApplication is the required entry point that binds the Application model to the macOS host; a null app cannot be set as the current application. The nameof produces the terse message 'application'.
Source
Thrown at src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs:29
Application _application;
bool _isSuspended;
static int _storyboardMainMenuCount;
public Func<MenuItem, NSMenuItem> NativeMenuItemCreator { get; set; }
public abstract NSWindow MainWindow { get; }
protected override void Dispose(bool disposing)
{
if (disposing && _application != null)
_application.PropertyChanged -= ApplicationOnPropertyChanged;
base.Dispose(disposing);
}
protected void LoadApplication(Application application)
{
if (application == null)
throw new ArgumentNullException(nameof(application));
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)View on GitHub (pinned to f377ff1c5e)
Solutions
- Ensure a non-null Application is constructed: LoadApplication(new App()); where App derives from Application.
- If using DI, resolve and null-check the Application before calling LoadApplication.
- Add a guard: if (app == null) throw new InvalidOperationException("App not built"); before LoadApplication to give a clearer message at the source.
Example fix
// before LoadApplication(_app); // _app is null // after _app = new App(); LoadApplication(_app);
Defensive patterns
Strategy: validation
Validate before calling
var app = BuildApp(); // never null
if (app == null) throw new InvalidOperationException("App construction failed");
LoadApplication(app); Type guard
static bool IsValidApp(Application a) => a != null;
Prevention
- Construct the Application inline at the LoadApplication call site.
- Null-check DI-resolved apps before loading.
- Fail loudly at construction rather than passing null through.
When it happens
Trigger: Calling LoadApplication(null) in the app delegate, e.g. because the Application instance was not constructed (constructor threw, field not assigned, or DI returned null).
Common situations: DI/build error producing a null Application. Conditional construction: LoadApplication(_app) where _app stayed null in a code path. Refactor that moved Application creation into a method returning null on failure.
Related errors
- call Forms.Init() before this
- You MUST invoke LoadApplication () before calling base.Finis
- NavigationPage must have a root Page before being used. Eith
- NavigationPage must have a root Page before being used. Eith
- Please provide a main window in your app
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/7aa8a23e296b12b1.
Report an issue: GitHub.