dotnet/maui · error · ArgumentException
Element is not of type CheckBox
Error message
Element is not of type CheckBox
What it means
Thrown by CheckBoxRendererBase.SetElement when the VisualElement passed to the renderer is not a CheckBox. The AppCompat renderer for CheckBox is hard-bound to the CheckBox controls type; any other element type is a registration or wiring mistake. The guard runs before any property subscription so the renderer never enters an invalid state.
Source
Thrown at src/Compatibility/Core/src/Android/AppCompat/CheckBoxRendererBase.cs:107
{
if (_disposed)
{
return new SizeRequest();
}
Measure(widthConstraint, heightConstraint);
return new SizeRequest(new Size(MeasuredWidth, MeasuredHeight), MinimumSize());
}
void IVisualElementRenderer.SetElement(VisualElement element)
{
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}
if (!(element is CheckBox checkBox))
{
throw new ArgumentException("Element is not of type " + typeof(CheckBox), nameof(element));
}
CheckBox oldElement = Element;
Element = checkBox;
Performance.Start(out string reference);
if (oldElement != null)
{
oldElement.PropertyChanged -= OnElementPropertyChanged;
}
element.PropertyChanged += OnElementPropertyChanged;
if (_tracker == null)
{
_tracker = new VisualElementTracker(this);
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Verify the ExportRenderer/ handler registration maps CheckBox (and only CheckBox) to CheckBoxRendererBase-derived types.
- Check that the element passed to the renderer is actually a CheckBox instance and not a subclass of a different control.
- If you need a custom checkbox-like control, subclass CheckBox or register a dedicated renderer for your custom type rather than reusing CheckBoxRendererBase.
Example fix
// before [assembly: ExportRenderer(typeof(MyToggle), typeof(CheckBoxRenderer))] // after [assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))] [assembly: ExportRenderer(typeof(MyToggle), typeof(MyToggleRenderer))]
Defensive patterns
Strategy: type-guard
Type guard
static bool IsCheckBoxElement(VisualElement element) => element is CheckBox;
Prevention
- Audit all [assembly: ExportRenderer(...)] attributes in the solution and ensure each maps the correct control type to its renderer.
- Add a unit test that resolves the renderer for CheckBox and asserts the returned element type matches.
- When subclassing controls, register a dedicated renderer for the subclass rather than reusing CheckBox's.
When it happens
Trigger: A custom handler/ registrar maps the wrong renderer to CheckBox, or a custom VisualElementRenderer is manually fed a non-CheckBox element. Also occurs when a custom control subclasses a different type but is erroneously registered against CheckBox in the platform registrar.
Common situations: Misconfiguring ExportRenderer attributes (e.g., [assembly: ExportRenderer(typeof(MySwitch), typeof(CheckBoxRenderer))]). Version mismatches where a control assembly exports a renderer for a type that was renamed or moved. Manually invoking SetElement with the wrong element instance in test harnesses.
Related errors
- Element is not of type ImageButton
- element must be of type RadioButton
- {nameof(element)} must be of type {typeof(IndicatorView).Nam
- {nameof(element)} must be of type {typeof(ItemsView).Name}
- {nameof(element)} must be of type {nameof(Button)}
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/38c7eb3004ba599d.
Report an issue: GitHub.