dotnet/maui · error · InvalidOperationException
ViewCell must have a {nameof(cell.View)}
Error message
ViewCell must have a {nameof(cell.View)} What it means
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.
Source
Thrown at src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs:44
return container;
}
BindableProperty unevenRows = null, rowHeight = null;
if (ParentView is TableView)
{
unevenRows = TableView.HasUnevenRowsProperty;
rowHeight = TableView.RowHeightProperty;
}
else if (ParentView is ListView)
{
cell.IsContextActionsLegacyModeEnabled = item.On<PlatformConfiguration.Android>().GetIsContextActionsLegacyModeEnabled();
unevenRows = ListView.HasUnevenRowsProperty;
rowHeight = ListView.RowHeightProperty;
}
if (cell.View == null)
throw new InvalidOperationException($"ViewCell must have a {nameof(cell.View)}");
IVisualElementRenderer view = Platform.CreateRenderer(cell.View, context);
Platform.SetRenderer(cell.View, view);
cell.View.IsPlatformEnabled = true;
var c = new ViewCellContainer(context, view, cell, ParentView, unevenRows, rowHeight);
Performance.Stop(reference, "GetCellCore");
return c;
}
[Obsolete("Use Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer.ViewCellContainer instead")]
internal class ViewCellContainer : ViewGroup, INativeElementView
{
readonly View _parent;
readonly BindableProperty _rowHeight;
readonly BindableProperty _unevenRows;
IVisualElementRenderer _view;View on GitHub (pinned to f377ff1c5e)
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.
Example fix
<!-- before -->
<ViewCell>
<Label Text="{Binding Name}" />
</ViewCell>
<!-- after -->
<ViewCell>
<View>
<Label Text="{Binding Name}" />
</View>
</ViewCell> Defensive patterns
Strategy: validation
Validate before calling
// In a cell factory, verify View is set before returning the cell.
ViewCell CreateCell()
{
var cell = new ViewCell
{
View = new StackLayout { Children = { new Label { Text = "Item" } } }
};
if (cell.View == null)
throw new InvalidOperationException("ViewCell.View must be set.");
return cell;
} Type guard
static bool HasView(ViewCell cell) => cell?.View != null;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- View for cell must implement INativeElementView to enable re
- View for cell must implement {nameof(INativeElementView)} to
- ViewCell must have a View
- ItemTemplate count has exceeded the limit of {ViewTypeCount}
- Element is not of type CheckBox
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/cabe1f7b235fc60f.
Report an issue: GitHub.