{"record":{"id":"c6b98c710fdff46c","repo":"dotnet/maui","slug":"nameof-element-must-be-of-type-typeof-indicato","errorCode":null,"errorMessage":"{nameof(element)} must be of type {typeof(IndicatorView).Name}","messagePattern":"(.+?) must be of type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/CollectionView/IndicatorViewRenderer.cs","lineNumber":79,"sourceCode":"\t\t\tMeasure(widthConstraint, heightConstraint);\n\t\t\treturn new SizeRequest(new Size(MeasuredWidth, MeasuredHeight), new Size());\n\t\t}\n\n\t\tvoid IVisualElementRenderer.UpdateLayout()\n\t\t{\n\t\t\tTracker?.UpdateLayout();\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetElement(VisualElement element)\n\t\t{\n\t\t\tif (element == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(nameof(element));\n\t\t\t}\n\n\t\t\tif (!(element is IndicatorView))\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"{nameof(element)} must be of type {typeof(IndicatorView).Name}\");\n\t\t\t}\n\n\t\t\tvar oldElement = IndicatorView;\n\t\t\tvar newElement = (IndicatorView)element;\n\n\t\t\tTearDownOldElement(oldElement);\n\t\t\tSetUpNewElement(newElement);\n\n\t\t\tOnElementChanged(oldElement, newElement);\n\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetLabelFor(int? id)\n\t\t{\n\t\t\tif (_defaultLabelFor == null)\n\t\t\t{\n\t\t\t\t_defaultLabelFor = LabelFor;\n\t\t\t}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/CollectionView/IndicatorViewRenderer.cs#L61-L97","documentation":"The Android IndicatorViewRenderer's explicit IVisualElementRenderer.SetElement implementation only accepts an IndicatorView element. It first checks for null (ArgumentNullException) then verifies the type with `element is IndicatorView`; any other VisualElement subtype triggers this ArgumentException. The renderer is hard-bound to a single control type because it wires IndicatorView-specific setup/teardown.","triggerScenarios":"Calling renderer.SetElement() (directly or via the MAUI/Xamarin.Forms registrar/handler pipeline) with an element that is not an IndicatorView — e.g. a wrong ExportRenderer registration, a custom handler swap, or programmatic renderer reuse with a different control.","commonSituations":"A mismatched ExportRenderer attribute pairing a non-IndicatorView control with IndicatorViewRenderer, or a custom renderer deriving from IndicatorViewRenderer but bound to a different element type. Rare in normal use; usually a registration/migration artifact.","solutions":["Verify the ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer)) registration matches the element type actually passed.","Ensure you are not reusing an IndicatorViewRenderer instance for a different control.","If writing a subclass, override SetElement and keep the generic element type as IndicatorView."],"exampleFix":"// before — wrong registration\n[assembly: ExportRenderer(typeof(CollectionView), typeof(IndicatorViewRenderer))]\n// after\n[assembly: ExportRenderer(typeof(IndicatorView), typeof(IndicatorViewRenderer))]","handlingStrategy":"validation","validationCode":"void AttachIndicator(IVisualElementRenderer renderer, VisualElement element)\n{\n    if (renderer is not IVisualElementRenderer) throw new ArgumentException(\"renderer incompatible\");\n    if (element is null) throw new ArgumentNullException(nameof(element));\n    if (element is not IndicatorView)\n        throw new ArgumentException($\"Expected IndicatorView, got {element.GetType().Name}.\", nameof(element));\n    ((IVisualElementRenderer)renderer).SetElement(element);\n}","typeGuard":"static bool IsIndicatorViewRendererFor(VisualElement e) => e is IndicatorView;","tryCatchPattern":null,"preventionTips":["Audit all ExportRenderer attributes for renderer/control type alignment.","Do not manually call SetElement on framework renderers; let the registrar handle it.","Keep custom renderer subclasses generic-parameter-aligned with their control."],"tags":["android","renderer","type-mismatch","collectionview","maui-compat"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}