{"record":{"id":"7aa8a23e296b12b1","repo":"dotnet/maui","slug":"application","errorCode":null,"errorMessage":"application","messagePattern":"application","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs","lineNumber":29,"sourceCode":"\t\tApplication _application;\n\t\tbool _isSuspended;\n\t\tstatic int _storyboardMainMenuCount;\n\n\t\tpublic Func<MenuItem, NSMenuItem> NativeMenuItemCreator { get; set; }\n\t\tpublic abstract NSWindow MainWindow { get; }\n\n\t\tprotected override void Dispose(bool disposing)\n\t\t{\n\t\t\tif (disposing && _application != null)\n\t\t\t\t_application.PropertyChanged -= ApplicationOnPropertyChanged;\n\n\t\t\tbase.Dispose(disposing);\n\t\t}\n\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)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/FormsApplicationDelegate.cs#L11-L47","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nLoadApplication(_app); // _app is null\n\n// after\n_app = new App();\nLoadApplication(_app);","handlingStrategy":"validation","validationCode":"var app = BuildApp(); // never null\nif (app == null) throw new InvalidOperationException(\"App construction failed\");\nLoadApplication(app);","typeGuard":"static bool IsValidApp(Application a) => a != null;","tryCatchPattern":null,"preventionTips":["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."],"tags":["macos","argument-null","lifecycle","forms","maui","xamarin"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}