dotnet/maui · error · InvalidOperationException
View for cell must implement INativeElementView to enable re
Error message
View for cell must implement INativeElementView to enable recycling.
What it means
Thrown by the Android ListViewAdapter during RecycleElement recycling when the convertView returned by the platform does not implement INativeElementView. The recycling strategy reuses converted views and expects to retrieve the underlying Cell via INativeElementView.Element; if the view lacks this interface, recycling cannot proceed.
Source
Thrown at src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs:310
}
else
{
layout = new ConditionalFocusLayout(_context) { Orientation = Orientation.Vertical };
if (_layoutsCreated.TryGetValue(position, out ConditionalFocusLayout value))
DisposeOfConditionalFocusLayout(value);
_layoutsCreated[position] = layout;
}
}
if (((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) && convertView != null)
{
var boxedCell = convertView as INativeElementView;
if (boxedCell == null)
{
throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling.");
}
#pragma warning disable CS0618 // Type or member is obsolete
cell = (Cell)boxedCell.Element;
#pragma warning restore CS0618 // Type or member is obsolete
ICellController cellController = cell;
cellController.SendDisappearing();
int row = position;
var group = 0;
var templatedItems = TemplatedItemsView.TemplatedItems;
if (_listView.IsGroupingEnabled)
group = templatedItems.GetGroupIndexFromGlobal(position, out row);
var templatedList = templatedItems.GetGroup(group);
if (_listView.IsGroupingEnabled)
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Switch to ListViewCachingStrategy.RetainElement if the custom renderer cannot implement INativeElementView.
- Update/replace the custom cell renderer so its platform view implements INativeElementView and returns the Cell.
- Use a standard ViewCell with a MAUI handler instead of a custom renderer.
Example fix
// before listView.CachingStrategy = ListViewCachingStrategy.RecycleElement; listView.ItemTemplate = new DataTemplate(() => new MyLegacyCustomCell()); // after listView.CachingStrategy = ListViewCachingStrategy.RetainElement;
Defensive patterns
Strategy: validation
Validate before calling
// Choose a caching strategy compatible with your cell renderer
var strategy = cellRendererImplementsNativeElementView
? ListViewCachingStrategy.RecycleElement
: ListViewCachingStrategy.RetainElement;
listView.CachingStrategy = strategy; Prevention
- Ensure custom cell renderers implement INativeElementView before enabling RecycleElement.
- Fall back to RetainElement for legacy renderers.
- Prefer standard MAUI-handled ViewCells.
When it happens
Trigger: Using ListViewCachingStrategy.RecycleElement with a custom cell whose renderer/platform view does not implement INativeElementView. Mixing legacy custom renderers with the MAUI recycling path. A third-party cell renderer that returns a plain View from GetView.
Common situations: Porting a Xamarin.Forms custom renderer that returned a non-INativeElementView view. Using an older cell renderer package incompatible with RecycleElement. Custom ViewCell whose platform handler does not surface Element.
Related errors
- Implement INativeElementView on cell renderer: {ContentCell.
- ItemTemplate count has exceeded the limit of {ViewTypeCount}
- View for cell must implement INativeElementView to enable re
- ItemTemplate count has exceeded the limit of {ViewTypeCount}
- ViewCell must have a View
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/efd66f8e94a3413e.
Report an issue: GitHub.