{"record":{"id":"c23cdfeb07e0386c","repo":"dotnet/maui","slug":"element-must-be-of-type-frame-c23cdf","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/iOS/MaterialFrameRenderer.cs","lineNumber":77,"sourceCode":"\t\t\tApplyThemeIfNeeded();\n\t\t}\n\n\t\tpublic void SetElement(VisualElement element)\n\t\t{\n\t\t\t_cardScheme?.Dispose();\n\t\t\t_cardScheme = CreateCardScheme();\n\n\t\t\tvar oldElement = Element;\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\tif (element is null)\n\t\t\t\tElement = null;\n\t\t\telse\n\t\t\t\tElement = element as Frame ?? throw new ArgumentException(\"Element must be of type Frame.\");\n\n\t\t\tif (Element != null)\n\t\t\t{\n\t\t\t\tif (_packager == null)\n\t\t\t\t{\n\t\t\t\t\t_defaultCardScheme = CreateCardScheme();\n\n\t\t\t\t\t_packager = new VisualElementPackager(this);\n\t\t\t\t\t_packager.Load();\n\n\t\t\t\t\t_tracker = new VisualElementTracker(this);\n\n\t\t\t\t\t_events = new EventTracker(this);\n\t\t\t\t\t_events.LoadEvents(this);\n\t\t\t\t}\n\n\t\t\t\tElement.PropertyChanged += OnElementPropertyChanged;\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Material/src/iOS/MaterialFrameRenderer.cs#L59-L95","documentation":"MaterialFrameRenderer on iOS (Catalyst/iOS) renders a Frame using an MDCCard scheme from Material Components. Its SetElement method throws ArgumentException if the incoming element cannot be cast to Frame. The card-scheme styling, corner radius, and elevation logic are all Frame-specific.","triggerScenarios":"Calling SetElement on MaterialFrameRenderer with a non-Frame element. Occurs when the handler registrar dispatches the wrong element type, or when manually invoking SetElement with an incompatible control during custom embedding scenarios.","commonSituations":"Custom embedding code that reuses a MaterialFrameRenderer for a different element. MAUI migration where Frame was replaced by Border but the iOS renderer mapping was not updated. Conflicting ExportRenderer declarations across assemblies.","solutions":["Verify the iOS ExportRenderer maps Frame to MaterialFrameRenderer.","Ensure the element passed to SetElement is a Frame instance or derives from Frame.","In embedding scenarios, create the correct renderer type for the element you are embedding.","Audit for stale registrations after migration from Frame to Border."],"exampleFix":"// before\nrenderer.SetElement(myContentView); // not a Frame\n\n// after\nrenderer.SetElement(myFrame); // myFrame is of type Frame","handlingStrategy":"type-guard","validationCode":"if (element is not Frame frame)\n    throw new InvalidOperationException($\"Expected Frame, got {element?.GetType().Name}\");\niOSRenderer.SetElement(frame);","typeGuard":"static bool IsFrame(VisualElement? element) => element is Frame;","tryCatchPattern":null,"preventionTips":["In embedding scenarios, create the renderer type that matches the element you are embedding.","Verify iOS ExportRenderer maps Frame to MaterialFrameRenderer.","Update registrations when migrating from Frame to Border."],"tags":["maui","ios","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"}