dotnet/maui · error · InvalidOperationException

Implement INativeElementView on cell renderer

Error message

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

What it means

ContextActionCell.Element getter boxes ContentCell as INativeElementView and throws InvalidOperationException if it is not. The cell context-actions feature relies on the underlying cell renderer implementing INativeElementView so that the Xamarin Element can be retrieved; if the registered cell renderer type lacks that interface, context actions cannot function and the contract is broken.

Solutions

  1. Implement INativeElementView on the custom cell renderer (provide the Element property).
  2. Verify the renderer type reported in the message; register or fix the correct renderer.
  3. Avoid using ContextActions on cells whose renderers are not under your control.

Example fix

// before
public class MyCell : UITableViewCell { /* no INativeElementView */ }
// after
public class MyCell : UITableViewCell, INativeElementView
{
    public Element Element { get; set; }
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(ContentCell is INativeElementView))
    throw new InvalidOperationException($"Cell renderer {ContentCell.GetType()} must implement INativeElementView to use ContextActions.");

Type guard

static bool SupportsContextActions(UITableViewCell cell) => cell is INativeElementView;

Prevention

When it happens

Trigger: Using ContextActions on a Cell whose registered iOS cell renderer does not implement INativeElementView; a custom Cell renderer registered without INativeElementView; a ViewCell renderer replacement from a third party.

Common situations: Registering a custom cell renderer via [assembly: ExportCell] that forgets to implement INativeElementView; upgrading a renderer package that drops the interface; mixing ViewCell with custom renderers that bypass the default.

Related errors


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

Appendix: source

Thrown at src/Compatibility/Core/src/iOS/ContextActionCell.cs:77

		public bool IsOpen
		{
			get { return ScrollDelegate.IsOpen; }
		}

		ContextScrollViewDelegate ScrollDelegate
		{
			get { return (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);
		}

		public override void LayoutSubviews()
		{
			base.LayoutSubviews();

View on GitHub (pinned to f377ff1c5e)