{"record":{"id":"3931696c53d1cc9f","repo":"dotnet/maui","slug":"element-must-be-of-type-progressbar","errorCode":null,"errorMessage":"Element must be of type ProgressBar.","messagePattern":"Element must be of type ProgressBar\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Material/src/Android/MaterialProgressBarRenderer.cs","lineNumber":143,"sourceCode":"\t\t\t\tUpdateColors();\n\t\t}\n\n\t\tvoid UpdateColors()\n\t\t{\n\t\t\tif (Element == null || Control == null)\n\t\t\t\treturn;\n\n\t\t\tthis.ApplyProgressBarColors(Element.ProgressColor, Element.BackgroundColor);\n\t\t}\n\n\t\tvoid UpdateProgress() => Control.Progress = (int)(Element.Progress * MaximumValue);\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 ProgressBar) ?? throw new ArgumentException(\"Element must be of type ProgressBar.\");\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\tMeasure(widthConstraint, heightConstraint);\n\t\t\treturn new SizeRequest(new Size(Control.MeasuredWidth, Context.ToPixels(4)), new Size(Context.ToPixels(4), Context.ToPixels(4)));\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// IViewRenderer","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Material/src/Android/MaterialProgressBarRenderer.cs#L125-L161","documentation":"MaterialProgressBarRenderer renders Material Design ProgressBar elements on Android. SetElement casts the VisualElement to ProgressBar and throws ArgumentException if the element is not a ProgressBar. The renderer reads Element.Progress and Element.ProgressColor, which only exist on ProgressBar.","triggerScenarios":"A non-ProgressBar element is dispatched to MaterialProgressBarRenderer via a misconfigured registration. Common when ActivityIndicator and ProgressBar renderers are confused due to similar naming.","commonSituations":"Swapping ActivityIndicator and ProgressBar renderer registrations. Registering a custom progress-like control that does not derive from ProgressBar. MAUI migration mismatches.","solutions":["Verify ExportRenderer maps ProgressBar (not ActivityIndicator) to MaterialProgressBarRenderer.","Ensure custom progress controls derive from ProgressBar if they use this renderer.","Check for duplicate ProgressBar registrations across assemblies.","Review the `VisualMarker.Material` application targets."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(ActivityIndicator), typeof(MaterialProgressBarRenderer))]\n\n// after\n[assembly: ExportRenderer(typeof(ProgressBar), typeof(MaterialProgressBarRenderer))]","handlingStrategy":"type-guard","validationCode":"if (element is not ProgressBar)\n    throw new InvalidOperationException($\"Expected ProgressBar, got {element?.GetType().Name}\");\nrenderer.SetElement(element);","typeGuard":"static bool IsProgressBar(VisualElement? element) => element is ProgressBar;","tryCatchPattern":null,"preventionTips":["Distinguish ProgressBar from ActivityIndicator in ExportRenderer mappings.","Ensure custom progress controls derive from ProgressBar.","Verify no duplicate ProgressBar registrations across assemblies."],"tags":["maui","android","material","renderer","type-mismatch","progress-bar"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}