{"record":{"id":"9eb3730912566546","repo":"dotnet/maui","slug":"mainrenderer","errorCode":null,"errorMessage":"mainRenderer","messagePattern":"mainRenderer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/MacOS/ModalPageTracker.cs","lineNumber":18,"sourceCode":"using System;\nusing System.Threading.Tasks;\nusing System.Linq;\nusing AppKit;\nusing System.Collections.Generic;\n\nnamespace Microsoft.Maui.Controls.Compatibility.Platform.MacOS\n{\n\tinternal class ModalPageTracker : IDisposable\n\t{\n\t\tNSViewController _renderer;\n\t\tList<Page> _modals;\n\t\tbool _disposed;\n\n\t\tpublic ModalPageTracker(NSViewController mainRenderer)\n\t\t{\n\t\t\tif (mainRenderer == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(mainRenderer));\n\t\t\t_renderer = mainRenderer;\n\t\t\t_renderer.View.WantsLayer = true;\n\t\t\t_modals = new List<Page>();\n\t\t}\n\n\t\tpublic List<Page> ModalStack => _modals;\n\n\t\tpublic Task PushAsync(Page modal, bool animated)\n\t\t{\n\t\t\t_modals.Add(modal);\n\t\t\tmodal.DescendantRemoved += HandleChildRemoved;\n\t\t\tPlatform.NativeToolbarTracker.TryHide(modal as NavigationPage);\n\t\t\treturn PresentModalAsync(modal, animated);\n\t\t}\n\n\t\tpublic Task<Page> PopAsync(bool animated)\n\t\t{\n\t\t\tvar modal = _modals.LastOrDefault();","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/ModalPageTracker.cs#L1-L36","documentation":"ModalPageTracker's constructor requires a non-null NSViewController (the main renderer) because it immediately accesses _renderer.View.WantsLayer and uses the renderer to present modals. A null renderer means there is no host view to layer and present against, so it throws ArgumentNullException(nameof(mainRenderer)) (message 'mainRenderer').","triggerScenarios":"Constructing ModalPageTracker with null — typically inside Platform when the platform renderer/view controller is null. An internal failure to create the main renderer surfaces here. Unlikely to be reached by user code directly but reflects a malformed Platform setup.","commonSituations":"Custom Platform construction on macOS without a backing NSViewController. Test setup that instantiates ModalPageTracker with null. A failure earlier in Platform setup that left the renderer null.","solutions":["Ensure Platform is constructed with a valid NSViewController/renderer before any modal navigation occurs.","In tests, pass a real or mock NSViewController (with a non-null View) to ModalPageTracker.","Trace why the main renderer is null — it usually indicates an upstream Platform initialization problem."],"exampleFix":"// before\nvar tracker = new ModalPageTracker(null); // throws\n\n// after\nvar vc = new NSViewController { View = new NSView() };\nvar tracker = new ModalPageTracker(vc);","handlingStrategy":"validation","validationCode":"if (mainRenderer == null) throw new ArgumentNullException(nameof(mainRenderer));\nvar tracker = new ModalPageTracker(mainRenderer);","typeGuard":"static bool IsValidRenderer(NSViewController vc) => vc != null && vc.View != null;","tryCatchPattern":null,"preventionTips":["Construct Platform with a valid NSViewController.","In tests, supply a real or mock controller with a non-null View.","Treat a null main renderer as an upstream Platform failure."],"tags":["macos","argument-null","modal","internal","maui"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}