{"record":{"id":"efd66f8e94a3413e","repo":"dotnet/maui","slug":"view-for-cell-must-implement-inativeelementview-to-efd66f","errorCode":null,"errorMessage":"View for cell must implement INativeElementView to enable recycling.","messagePattern":"View for cell must implement INativeElementView to enable recycling\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs","lineNumber":310,"sourceCode":"\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlayout = new ConditionalFocusLayout(_context) { Orientation = Orientation.Vertical };\n\n\t\t\t\t\tif (_layoutsCreated.TryGetValue(position, out ConditionalFocusLayout value))\n\t\t\t\t\t\tDisposeOfConditionalFocusLayout(value);\n\n\t\t\t\t\t_layoutsCreated[position] = layout;\n\t\t\t\t}\n\t\t\t}\n\n\n\t\t\tif (((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) && convertView != null)\n\t\t\t{\n\t\t\t\tvar boxedCell = convertView as INativeElementView;\n\t\t\t\tif (boxedCell == null)\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException($\"View for cell must implement {nameof(INativeElementView)} to enable recycling.\");\n\t\t\t\t}\n#pragma warning disable CS0618 // Type or member is obsolete\n\t\t\t\tcell = (Cell)boxedCell.Element;\n#pragma warning restore CS0618 // Type or member is obsolete\n\n\t\t\t\tICellController cellController = cell;\n\t\t\t\tcellController.SendDisappearing();\n\n\t\t\t\tint row = position;\n\t\t\t\tvar group = 0;\n\t\t\t\tvar templatedItems = TemplatedItemsView.TemplatedItems;\n\t\t\t\tif (_listView.IsGroupingEnabled)\n\t\t\t\t\tgroup = templatedItems.GetGroupIndexFromGlobal(position, out row);\n\n\t\t\t\tvar templatedList = templatedItems.GetGroup(group);\n\n\t\t\t\tif (_listView.IsGroupingEnabled)\n\t\t\t\t{","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs#L292-L328","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlistView.CachingStrategy = ListViewCachingStrategy.RecycleElement;\nlistView.ItemTemplate = new DataTemplate(() => new MyLegacyCustomCell());\n\n// after\nlistView.CachingStrategy = ListViewCachingStrategy.RetainElement;","handlingStrategy":"validation","validationCode":"// Choose a caching strategy compatible with your cell renderer\nvar strategy = cellRendererImplementsNativeElementView\n    ? ListViewCachingStrategy.RecycleElement\n    : ListViewCachingStrategy.RetainElement;\nlistView.CachingStrategy = strategy;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure custom cell renderers implement INativeElementView before enabling RecycleElement.","Fall back to RetainElement for legacy renderers.","Prefer standard MAUI-handled ViewCells."],"tags":["maui","listview","android","recycling","custom-renderer","inativeelementview"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}