{"record":{"id":"3e21d2604f4afca8","repo":"dotnet/maui","slug":"element-must-be-of-type-frame","errorCode":null,"errorMessage":"Element must be of type Frame","messagePattern":"Element must be of type Frame","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/FastRenderers/FrameRenderer.cs","lineNumber":79,"sourceCode":"\n\t\t\t\t_element?.SendViewInitialized(Control);\n\t\t\t}\n\t\t}\n\n\t\tVisualElement IVisualElementRenderer.Element => Element;\n\t\tAView IVisualElementRenderer.View => this;\n\n\t\tSizeRequest IVisualElementRenderer.GetDesiredSize(int widthMeasureSpec, int heightMeasureSpec)\n\t\t{\n\t\t\tContext context = Context;\n\t\t\treturn new SizeRequest(new Size(context.ToPixels(20), context.ToPixels(20)));\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetElement(VisualElement element)\n\t\t{\n\t\t\tvar frame = element as Frame;\n\t\t\tif (frame == null)\n\t\t\t\tthrow new ArgumentException(\"Element must be of type Frame\");\n\t\t\tElement = frame;\n\t\t\t_motionEventHelper.UpdateElement(frame);\n\n\t\t\tif (!string.IsNullOrEmpty(Element.AutomationId))\n\t\t\t\tContentDescription = Element.AutomationId;\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetLabelFor(int? id)\n\t\t{\n\t\t\tif (_defaultLabelFor == null)\n\t\t\t\t_defaultLabelFor = ViewCompat.GetLabelFor(this);\n\n\t\t\tViewCompat.SetLabelFor(this, (int)(id ?? _defaultLabelFor));\n\t\t}\n\n\t\tVisualElementTracker IVisualElementRenderer.Tracker => _visualElementTracker;\n\n\t\tvoid IVisualElementRenderer.UpdateLayout()","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/FastRenderers/FrameRenderer.cs#L61-L97","documentation":"FrameRenderer.SetElement uses an `as` cast and throws ArgumentException if the result is null (element is not a Frame). Unlike the null-then-is pattern used by other fast renderers, FrameRenderer does not separately guard against a null element, so a null element would surface as the same 'must be of type Frame' message.","triggerScenarios":"SetElement invoked with an element that is not a Frame (or, with the same message, a null element because the `as` yields null and there is no dedicated ArgumentNullException here).","commonSituations":"Wrong ExportRenderer registration for FrameRenderer; subclassing FrameRenderer and binding it to a non-Frame control; passing null during teardown paths.","solutions":["Register FrameRenderer only for Frame (or a Frame subclass).","Guard against passing null — the renderer lacks an explicit ArgumentNullException path, so callers must supply a non-null Frame.","Prefer the MAUI handler over the compatibility renderer where possible."],"exampleFix":"// before\nvar frame = element as Frame;\nif (frame == null)\n    throw new ArgumentException(\"Element must be of type Frame\");\n// after — also reject null explicitly\nif (element == null)\n    throw new ArgumentNullException(nameof(element));\nif (element is not Frame frame)\n    throw new ArgumentException(\"Element must be of type Frame\", nameof(element));","handlingStrategy":"validation","validationCode":"if (element is null) throw new ArgumentNullException(nameof(element));\nif (element is not Frame) throw new ArgumentException(\"Expected Frame.\", nameof(element));\n((IVisualElementRenderer)renderer).SetElement(element);","typeGuard":"static bool IsFrame(VisualElement e) => e is Frame;","tryCatchPattern":null,"preventionTips":["FrameRenderer has no dedicated null guard — always null-check before SetElement.","Register FrameRenderer only for Frame.","Avoid manual renderer reuse."],"tags":["android","renderer","type-mismatch","frame","fast-renderer","maui-compat"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}