{"record":{"id":"cabe1f7b235fc60f","repo":"dotnet/maui","slug":"viewcell-must-have-a-nameof-cell-view","errorCode":null,"errorMessage":"ViewCell must have a {nameof(cell.View)}","messagePattern":"ViewCell must have a (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs","lineNumber":44,"sourceCode":"\t\t\t\treturn container;\n\t\t\t}\n\n\t\t\tBindableProperty unevenRows = null, rowHeight = null;\n\t\t\tif (ParentView is TableView)\n\t\t\t{\n\t\t\t\tunevenRows = TableView.HasUnevenRowsProperty;\n\t\t\t\trowHeight = TableView.RowHeightProperty;\n\t\t\t}\n\t\t\telse if (ParentView is ListView)\n\t\t\t{\n\t\t\t\tcell.IsContextActionsLegacyModeEnabled = item.On<PlatformConfiguration.Android>().GetIsContextActionsLegacyModeEnabled();\n\n\t\t\t\tunevenRows = ListView.HasUnevenRowsProperty;\n\t\t\t\trowHeight = ListView.RowHeightProperty;\n\t\t\t}\n\n\t\t\tif (cell.View == null)\n\t\t\t\tthrow new InvalidOperationException($\"ViewCell must have a {nameof(cell.View)}\");\n\n\t\t\tIVisualElementRenderer view = Platform.CreateRenderer(cell.View, context);\n\t\t\tPlatform.SetRenderer(cell.View, view);\n\t\t\tcell.View.IsPlatformEnabled = true;\n\t\t\tvar c = new ViewCellContainer(context, view, cell, ParentView, unevenRows, rowHeight);\n\n\t\t\tPerformance.Stop(reference, \"GetCellCore\");\n\n\t\t\treturn c;\n\t\t}\n\n\t\t[Obsolete(\"Use Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer.ViewCellContainer instead\")]\n\t\tinternal class ViewCellContainer : ViewGroup, INativeElementView\n\t\t{\n\t\t\treadonly View _parent;\n\t\t\treadonly BindableProperty _rowHeight;\n\t\t\treadonly BindableProperty _unevenRows;\n\t\t\tIVisualElementRenderer _view;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs#L26-L62","documentation":"Thrown by ViewCellRenderer.GetCellCore when cell.View is null. A ViewCell must have a View (its content) set before it is rendered; the renderer needs to create a native renderer for cell.View. Without a View, there is nothing to display and the renderer cannot proceed.","triggerScenarios":"A ViewCell is used in a ListView/TableView DataTemplate but its View property was never assigned. In XAML, this happens when the <ViewCell> element has no child <View> or the child is misnamed. In code, it happens when ViewCell.View is not set before binding.","commonSituations":"XAML <ViewCell> missing the required <View> child element. Code-behind creating new ViewCell() without setting .View. DataTemplate returning a ViewCell whose View was conditionally cleared. Migrating a TextCell to a ViewCell and forgetting to add content.","solutions":["In XAML, ensure the ViewCell contains exactly one <View> child element with valid content.","In code, always set cell.View = new StackLayout { ... } (or other layout) before the cell is used.","Validate that the DataTemplate's ViewCell factory always produces a cell with a non-null View."],"exampleFix":"<!-- before -->\n<ViewCell>\n    <Label Text=\"{Binding Name}\" />\n</ViewCell>\n\n<!-- after -->\n<ViewCell>\n    <View>\n        <Label Text=\"{Binding Name}\" />\n    </View>\n</ViewCell>","handlingStrategy":"validation","validationCode":"// In a cell factory, verify View is set before returning the cell.\nViewCell CreateCell()\n{\n    var cell = new ViewCell\n    {\n        View = new StackLayout { Children = { new Label { Text = \"Item\" } } }\n    };\n    if (cell.View == null)\n        throw new InvalidOperationException(\"ViewCell.View must be set.\");\n    return cell;\n}","typeGuard":"static bool HasView(ViewCell cell) => cell?.View != null;","tryCatchPattern":null,"preventionTips":["Always include exactly one <View> child in XAML <ViewCell> elements.","In code, set ViewCell.View before the cell is used; assert non-null in debug builds.","Add a XAML analyzer rule that flags ViewCell without a View child.","Use TextCell when only text is needed, to avoid the View requirement entirely."],"tags":["android","viewcell","listview","xaml","renderer"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}