{"record":{"id":"94f070a6ce2434af","repo":"dotnet/maui","slug":"element-must-be-of-type-radiobutton","errorCode":null,"errorMessage":"element must be of type RadioButton","messagePattern":"element must be of type RadioButton","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/AppCompat/RadioButtonRenderer.cs","lineNumber":78,"sourceCode":"\t\t\t((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus);\n\t\t}\n\n\t\tSizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)\n\t\t{\n\t\t\tMeasure(widthConstraint, heightConstraint);\n\t\t\treturn new SizeRequest(new Size(MeasuredWidth, MeasuredHeight));\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 RadioButton))\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"{nameof(element)} must be of type {nameof(RadioButton)}\");\n\t\t\t}\n\n\t\t\tRadioButton oldElement = Element;\n\t\t\tElement = (RadioButton)element;\n\n\t\t\tPerformance.Start(out string reference);\n\n\t\t\tif (oldElement != null)\n\t\t\t{\n\t\t\t\toldElement.PropertyChanged -= OnElementPropertyChanged;\n\t\t\t}\n\n\t\t\telement.PropertyChanged += OnElementPropertyChanged;\n\n\t\t\tif (_tracker == null)\n\t\t\t{\n\t\t\t\t// Can't set up the tracker in the constructor because it access the Element (for now)\n\t\t\t\tSetTracker(new VisualElementTracker(this));","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/AppCompat/RadioButtonRenderer.cs#L60-L96","documentation":"Thrown by RadioButtonRenderer.SetElement when the VisualElement passed to the renderer is not a RadioButton. The AppCompat RadioButton renderer is bound exclusively to the RadioButton control type; receiving any other element indicates a misregistered handler or incorrect element assignment.","triggerScenarios":"An ExportRenderer attribute maps a non-RadioButton type to RadioButtonRenderer, or the renderer is manually invoked with the wrong element. Also surfaces when a custom control masquerading as a radio button is registered against the wrong renderer.","commonSituations":"Confusing RadioButton with CheckBox or a custom toggle control in ExportRenderer attributes. Version upgrades where RadioButton's namespace changed. Reusing RadioButtonRenderer for a custom selection control without subclassing RadioButton.","solutions":["Verify the ExportRenderer/handler registration maps RadioButton (and only RadioButton) to RadioButtonRenderer.","Confirm the element passed is a RadioButton, not a CheckBox, Switch, or custom control.","For custom radio-button-like controls, subclass RadioButton or register a dedicated renderer for your type."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(CheckBox), typeof(RadioButtonRenderer))]\n\n// after\n[assembly: ExportRenderer(typeof(RadioButton), typeof(RadioButtonRenderer))]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsRadioButtonElement(VisualElement element) => element is RadioButton;","tryCatchPattern":null,"preventionTips":["Audit ExportRenderer attributes; RadioButtonRenderer must map only to RadioButton.","Distinguish RadioButton from CheckBox and Switch in registrations.","Add a renderer-resolution unit test asserting the correct element type for each registered renderer."],"tags":["android","renderer","radiobutton","type-mismatch","registration"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}