dotnet/maui · error · ArgumentException
{element?.GetType().FullName} is not compatible. element mus
Error message
{element?.GetType().FullName} is not compatible. element must be of type ActivityIndicator. What it means
MaterialActivityIndicatorRenderer is the Material Design renderer for ActivityIndicator on Android. Its SetElement implementation casts the incoming VisualElement to ActivityIndicator and throws ArgumentException if the cast fails. This enforces the one-to-one mapping between renderer and element type — the renderer cannot track or render an incompatible element.
Source
Thrown at src/Compatibility/Material/src/Android/MaterialActivityIndicatorRenderer.cs:170
{
if (Element != null && _control != null)
_control.SetBackground(Element.BackgroundColor, Element.Background);
}
// IVisualElementRenderer
VisualElement IVisualElementRenderer.Element => Element;
VisualElementTracker IVisualElementRenderer.Tracker => _visualElementTracker;
AView IVisualElementRenderer.View => this;
SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)
{
_control.Measure(widthConstraint, heightConstraint);
return new SizeRequest(new Size(Control.MeasuredWidth, Control.MeasuredHeight), new Size());
}
void IVisualElementRenderer.SetElement(VisualElement element) =>
Element = (element as ActivityIndicator) ??
throw new ArgumentException($"{element?.GetType().FullName} is not compatible. {nameof(element)} must be of type {nameof(ActivityIndicator)}.");
void IVisualElementRenderer.SetLabelFor(int? id)
{
if (_defaultLabelFor == null)
_defaultLabelFor = ViewCompat.GetLabelFor(this);
ViewCompat.SetLabelFor(this, (int)(id ?? _defaultLabelFor));
}
void IVisualElementRenderer.UpdateLayout() =>
_visualElementTracker?.UpdateLayout();
// IViewRenderer
void IViewRenderer.MeasureExactly() =>
ViewRenderer.MeasureExactly(_control, Element, Context);
// ITabStop
AView ITabStop.TabStop => _control;View on GitHub (pinned to f377ff1c5e)
Solutions
- Verify the ExportRenderer/HandlerRegistration attribute pairs ActivityIndicator with MaterialActivityIndicatorRenderer.
- Ensure any custom control you want rendered by this renderer derives from ActivityIndicator.
- Check for duplicate or conflicting renderer registrations across assemblies.
- If using the Material visual (`VisualMarker.Material`), confirm the element type is one Material supports.
Example fix
// before (wrong mapping) [assembly: ExportRenderer(typeof(ProgressBar), typeof(MaterialActivityIndicatorRenderer))] // after (correct mapping) [assembly: ExportRenderer(typeof(ActivityIndicator), typeof(MaterialActivityIndicatorRenderer))]
Defensive patterns
Strategy: type-guard
Validate before calling
if (element is not ActivityIndicator)
throw new InvalidOperationException($"Expected ActivityIndicator, got {element?.GetType().Name}");
renderer.SetElement(element); Type guard
static bool IsActivityIndicator(VisualElement? element) => element is ActivityIndicator;
Prevention
- Double-check ExportRenderer/HandlerRegistration pairs element type to renderer type.
- Ensure custom controls derive from the correct base element (ActivityIndicator).
- Audit renderer registrations across all assemblies during build.
When it happens
Trigger: The MAUI handler/renderer registry dispatches a non-ActivityIndicator element to MaterialActivityIndicatorRenderer. This happens when ExportRenderer or RegisterHandler registrations are misconfigured, or when a custom registrar maps the wrong element type to this renderer.
Common situations: Custom ExportRenderer attributes that incorrectly pair an element type with the wrong renderer. Migrating from Xamarin.Forms to MAUI and leaving stale renderer registrations. Using a Material visual with a custom control that does not derive from ActivityIndicator.
Related errors
- Element must be of type Button.
- Element must be of type Frame.
- Element must be of type ProgressBar.
- Element must be of type Slider.
- Element must be of type Frame.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/7e3520dd92c98131.
Report an issue: GitHub.