dotnet/maui · error · InvalidOperationException
No UIViewController found to present.
Error message
No UIViewController found to present.
What it means
ContextActionCell throws InvalidOperationException("No UIViewController found to present.") when its controller-walk returns null. iOS requires a UIViewController to present a UIAlertController for context actions; if the cell is not attached to any window/view hierarchy, no controller can be located and the action sheet cannot be shown.
Source
Thrown at src/Compatibility/Core/src/iOS/ContextActionCell.cs:340
continue;
var item = _cell.ContextActions[i];
var weakItem = new WeakReference<MenuItem>(item);
var action = UIAlertAction.Create(item.Text, UIAlertActionStyle.Default, a =>
{
if (_scroller == null)
return;
_scroller.SetContentOffset(new PointF(0, 0), true);
if (weakItem.TryGetTarget(out MenuItem mi))
((IMenuItemController)mi).Activate();
});
actionSheet.AddAction(action);
}
var controller = GetController();
if (controller == null)
throw new InvalidOperationException("No UIViewController found to present.");
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone || (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && actionSheet.PopoverPresentationController == null))
{
var cancel = UIAlertAction.Create(StringResources.Cancel, UIAlertActionStyle.Cancel, null);
actionSheet.AddAction(cancel);
}
else
{
if (actionSheet.PopoverPresentationController != null)
{
actionSheet.PopoverPresentationController.SourceView = _tableView;
actionSheet.PopoverPresentationController.SourceRect = sourceRect;
}
}
controller.PresentViewController(actionSheet, true, null);
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Only trigger context actions after the cell's ListView is visible in a windowed UIViewController.
- Cancel pending context actions on cell recycling/detachment.
- In tests/hosted scenarios, ensure the page is presented before invoking context action menu items.
Example fix
// before
((IMenuItemController)menuItem).Activate();
// after
if (GetController(cell) != null)
((IMenuItemController)menuItem).Activate(); Defensive patterns
Strategy: validation
Validate before calling
// Ensure a controller exists before activating context actions. var controller = FindViewController(cell); if (controller == null) return; // not yet presented
Type guard
static bool IsCellPresented(UITableViewCell cell) =>
cell.Window != null && FindViewController(cell) != null; Prevention
- Trigger context actions only when the ListView is visible in a window.
- Cancel pending context actions on cell recycle.
- Avoid invoking MenuItem.Activate outside the live UI.
When it happens
Trigger: Activating context actions on a cell whose ViewCell/ListView is not yet in a windowed UIViewController hierarchy; calling Activate on a MenuItem for a cell that was detached, recycled, or never displayed.
Common situations: Programmatically triggering a MenuItem.Activate() outside the live UI; cells recycled while a context action is still pending; modal transitions detaching the view; tests invoking context actions without a hosted controller.
Related errors
- Implement INativeElementView on cell renderer: {ContentCell.
- You MUST invoke LoadApplication () before calling base.Finis
- call Forms.Init() before this
- InsertPageBefore is not supported globally on iOS, please us
- PopAsync is not supported globally on iOS, please use a Navi
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e10d0642286c6e41.
Report an issue: GitHub.