{"record":{"id":"852440e71158a944","repo":"dotnet/maui","slug":"viewcell-must-have-a-view","errorCode":null,"errorMessage":"ViewCell must have a View","messagePattern":"ViewCell must have a View","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Cells/ViewCellRenderer.cs","lineNumber":167,"sourceCode":"\n\t\t\t\t\tif (_viewCell != null)\n\t\t\t\t\t{\n\t\t\t\t\t\t_viewCell.PropertyChanged -= ViewCellPropertyChanged;\n\t\t\t\t\t\t_viewCell.View.MeasureInvalidated -= OnMeasureInvalidated;\n\t\t\t\t\t\tSetRealCell(_viewCell, null);\n\t\t\t\t\t}\n\t\t\t\t\t_viewCell = null;\n\t\t\t\t}\n\n\t\t\t\t_disposed = true;\n\n\t\t\t\tbase.Dispose(disposing);\n\t\t\t}\n\n\t\t\tIVisualElementRenderer GetNewRenderer()\n\t\t\t{\n\t\t\t\tif (_viewCell.View == null)\n\t\t\t\t\tthrow new InvalidOperationException($\"ViewCell must have a {nameof(_viewCell.View)}\");\n\n\t\t\t\tvar newRenderer = Platform.CreateRenderer(_viewCell.View);\n\t\t\t\t_rendererRef = new WeakReference<IVisualElementRenderer>(newRenderer);\n\t\t\t\tContentView.AddSubview(newRenderer.NativeView);\n\t\t\t\treturn newRenderer;\n\t\t\t}\n\n\t\t\tvoid UpdateCell(ViewCell cell)\n\t\t\t{\n\t\t\t\tPerformance.Start(out string reference);\n\n\t\t\t\tvar oldCell = _viewCell;\n\t\t\t\tif (oldCell != null)\n\t\t\t\t{\n\t\t\t\t\tDevice.BeginInvokeOnMainThread(oldCell.SendDisappearing);\n\t\t\t\t\toldCell.PropertyChanged -= ViewCellPropertyChanged;\n\t\t\t\t\toldCell.View.MeasureInvalidated -= OnMeasureInvalidated;\n\t\t\t\t}","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Cells/ViewCellRenderer.cs#L149-L185","documentation":"ViewCellRenderer.GetNewRenderer throws InvalidOperationException when ViewCell.View is null. The renderer needs a View to create its child platform renderer via Platform.CreateRenderer. This fires during cell recycling when UpdateCell is called on a ViewCell that has no View content.","triggerScenarios":"A DataTemplate returns a ViewCell without setting the View property; a ViewCell in XAML with no child element; a cell template selector returns an incomplete ViewCell; programmatic ViewCell creation without View assignment.","commonSituations":"Empty or placeholder DataTemplate; conditional DataTemplateSelector that doesn't always set View; ViewCell defined in XAML with commented-out or missing content; ViewCell.View set to null during recycling.","solutions":["Ensure every ViewCell has a non-null View: <ViewCell><StackLayout>...</StackLayout></ViewCell>","Validate DataTemplate output before returning: if (cell.View == null) cell.View = new ContentView();","Use DataTemplateSelector implementations that always provide a complete ViewCell with View set","Add a fallback View in DataTemplate creation code"],"exampleFix":"// before\nvar cell = new ViewCell(); // View is null\ncell.SetBinding(...); // later throws when rendered\n\n// after\nvar cell = new ViewCell\n{\n    View = new StackLayout { Children = { new Label { Text = \"Item\" } } }\n};","handlingStrategy":"validation","validationCode":"// Before using a ViewCell, verify View is set\nif (cell.View == null)\n    cell.View = new ContentView { Content = new Label { Text = \"Loading...\" } };\n// Safe to render now","typeGuard":"static bool HasView(ViewCell cell)\n{\n    return cell?.View != null;\n}","tryCatchPattern":null,"preventionTips":["Always set ViewCell.View in XAML: <ViewCell><ContentView>...</ContentView></ViewCell>","Validate DataTemplate output in DataTemplateSelector implementations","Provide fallback Views for all cell templates","Unit test DataTemplates to ensure ViewCell.View is never null"],"tags":["rendering","cells","ios","validation","viewcell"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}