dotnet/maui · error · ArgumentNullException
mainRenderer
Error message
mainRenderer
What it means
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').
Source
Thrown at src/Compatibility/Core/src/MacOS/ModalPageTracker.cs:18
using System;
using System.Threading.Tasks;
using System.Linq;
using AppKit;
using System.Collections.Generic;
namespace Microsoft.Maui.Controls.Compatibility.Platform.MacOS
{
internal class ModalPageTracker : IDisposable
{
NSViewController _renderer;
List<Page> _modals;
bool _disposed;
public ModalPageTracker(NSViewController mainRenderer)
{
if (mainRenderer == null)
throw new ArgumentNullException(nameof(mainRenderer));
_renderer = mainRenderer;
_renderer.View.WantsLayer = true;
_modals = new List<Page>();
}
public List<Page> ModalStack => _modals;
public Task PushAsync(Page modal, bool animated)
{
_modals.Add(modal);
modal.DescendantRemoved += HandleChildRemoved;
Platform.NativeToolbarTracker.TryHide(modal as NavigationPage);
return PresentModalAsync(modal, animated);
}
public Task<Page> PopAsync(bool animated)
{
var modal = _modals.LastOrDefault();View on GitHub (pinned to f377ff1c5e)
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.
Example fix
// before
var tracker = new ModalPageTracker(null); // throws
// after
var vc = new NSViewController { View = new NSView() };
var tracker = new ModalPageTracker(vc); Defensive patterns
Strategy: validation
Validate before calling
if (mainRenderer == null) throw new ArgumentNullException(nameof(mainRenderer)); var tracker = new ModalPageTracker(mainRenderer);
Type guard
static bool IsValidRenderer(NSViewController vc) => vc != null && vc.View != null;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- application
- No Modal pages found in the stack, make sure you pushed a mo
- call Forms.Init() before this
- Please provide a main window in your app
- You MUST invoke LoadApplication () before calling base.Finis
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/9eb3730912566546.
Report an issue: GitHub.