dotnet/maui · error · InvalidOperationException

Implement INativeElementView on cell renderer: {ContentCell.

Error message

Implement INativeElementView on cell renderer: {ContentCell.GetType().AssemblyQualifiedName}

What it means

Thrown by the iOS ContextActionCell.Element getter when ContentCell does not implement INativeElementView. Context actions need to reach the underlying Cell element through this interface; a custom/legacy cell renderer lacking it cannot supply context actions.

Source

Thrown at src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ContextActionCell.cs:71

		public ContextActionsCell(string templateId) : base(UITableViewCellStyle.Default, Key + templateId)
		{
		}

		public UITableViewCell ContentCell { get; private set; }

		public bool IsOpen => ScrollDelegate.IsOpen;

		ContextScrollViewDelegate ScrollDelegate => (ContextScrollViewDelegate)_scroller.Delegate;

		Element INativeElementView.Element
		{
			get
			{
				var boxedCell = ContentCell as INativeElementView;
				if (boxedCell == null)
				{
					throw new InvalidOperationException($"Implement {nameof(INativeElementView)} on cell renderer: {ContentCell.GetType().AssemblyQualifiedName}");
				}

				return boxedCell.Element;
			}
		}

		public void Close()
		{
			if (_scroller == null)
				return;

			_scroller.ContentOffset = new PointF(0, 0);
		}

		static void FillRect(UIGraphicsImageRendererContext ctx, RectangleF rect, CGColor color)
		{
			var context = ctx.CGContext;
			context.SetFillColor(color);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use a built-in cell type (TextCell, SwitchCell, ViewCell) whose renderer implements INativeElementView.
  2. Update the custom cell renderer so its platform view implements INativeElementView and returns the Cell.
  3. Remove context actions from cells whose renderers cannot satisfy the contract.

Example fix

// before
<TableView>
  <TableRoot>
    <TableSection>
      <MyLegacyCustomCell>
        <ViewCell.ContextActions>
          <MenuItem Text="Delete" />
        </ViewCell.ContextActions>
      </MyLegacyCustomCell>
    </TableSection>
  </TableRoot>
</TableView>

// after — use built-in TextCell which supports context actions
<TextCell Text="Item">
  <TextCell.ContextActions>
    <MenuItem Text="Delete" />
  </TextCell.ContextActions>
</TextCell>
Defensive patterns

Strategy: validation

Validate before calling

// Use a built-in cell type whose renderer implements INativeElementView
if (!(contentCell is INativeElementView))
    throw new InvalidOperationException($"{contentCell.GetType()} cannot host context actions; use a built-in cell.");

Type guard

static bool SupportsContextActions(Cell c) =>
    c.ToHandler(c.FindMauiContext())?.PlatformView is INativeElementView;

Prevention

When it happens

Trigger: Attaching context actions to a cell whose platform renderer does not implement INativeElementView. Using a custom iOS cell renderer that returns a plain UITableViewCell. Mixing a legacy cell with the MAUI context-action pipeline.

Common situations: Porting a Xamarin.Forms iOS custom cell renderer. Third-party cell renderers that bypass the INativeElementView contract. Enabling context actions on a cell type whose renderer was never updated for MAUI.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/a2528f4ae82d4f04. Report an issue: GitHub.