{"record":{"id":"c1c15ca47520b895","repo":"dotnet/maui","slug":"element-must-be-of-type-frame-c1c15c","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/Material/src/Android/MaterialFrameRenderer.cs","lineNumber":283,"sourceCode":"\t\t\t\tif (_defaultBackgroundDrawable == null)\n\t\t\t\t\t_defaultBackgroundDrawable = Background;\n\n\t\t\t\t_backgroundGradientDrawable = new GradientDrawable();\n\t\t\t\t_backgroundGradientDrawable.SetShape(ShapeType.Rectangle);\n\n\t\t\t\t_backgroundGradientDrawable.SetCornerRadius(Radius);\n\t\t\t\t_backgroundGradientDrawable.UpdateBackground(bgBrush, Height, Width);\n\n\t\t\t\tBackground = _backgroundGradientDrawable;\n\t\t\t}\n\t\t}\n\n\t\t// IVisualElementRenderer\n\t\tVisualElement IVisualElementRenderer.Element => Element;\n\t\tVisualElementTracker IVisualElementRenderer.Tracker => _visualElementTracker;\n\t\tAView IVisualElementRenderer.View => this;\n\t\tvoid IVisualElementRenderer.SetElement(VisualElement element) =>\n\t\t\tElement = (element as Frame) ?? throw new ArgumentException(\"Element must be of type Frame.\");\n\t\tvoid IVisualElementRenderer.UpdateLayout() =>\n\t\t\t_visualElementTracker?.UpdateLayout();\n\n\t\tSizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)\n\t\t{\n\t\t\tvar context = Context;\n\t\t\treturn new SizeRequest(new Size(context.ToPixels(20), context.ToPixels(20)));\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\t// IEffectControlProvider","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Material/src/Android/MaterialFrameRenderer.cs#L265-L301","documentation":"MaterialFrameRenderer renders Material Design Frame elements on Android. SetElement casts the VisualElement to Frame and throws ArgumentException on mismatch. The renderer applies Material card-scheme corner radius and elevation logic specific to Frame, so an incompatible element cannot be processed.","triggerScenarios":"The handler dispatch sends a non-Frame element to MaterialFrameRenderer. Happens with incorrect ExportRenderer registrations or when migrating a custom ContentView to be rendered by the Frame renderer.","commonSituations":"Confusing Frame with ContentView or Border in renderer registrations. MAUI migration where Frame was replaced by Border but the renderer mapping was not updated. Custom layouts accidentally mapped to the Frame renderer.","solutions":["Confirm the ExportRenderer attribute maps Frame to MaterialFrameRenderer.","If migrating from Frame to Border/ContentView, update both the element type and the renderer accordingly.","Ensure no custom element type without a Frame base is registered against this renderer.","Check for conflicting registrations across multiple assemblies."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(ContentView), typeof(MaterialFrameRenderer))]\n\n// after\n[assembly: ExportRenderer(typeof(Frame), typeof(MaterialFrameRenderer))]","handlingStrategy":"type-guard","validationCode":"if (element is not Frame)\n    throw new InvalidOperationException($\"Expected Frame, got {element?.GetType().Name}\");\nrenderer.SetElement(element);","typeGuard":"static bool IsFrame(VisualElement? element) => element is Frame;","tryCatchPattern":null,"preventionTips":["Confirm ExportRenderer maps Frame to MaterialFrameRenderer.","Update registrations when migrating from Frame to Border/ContentView.","Audit for conflicting Frame registrations across assemblies."],"tags":["maui","android","material","renderer","type-mismatch","frame"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}