{"record":{"id":"79a37c5a09222e14","repo":"dotnet/maui","slug":"element-is-not-of-type-typeof-image","errorCode":null,"errorMessage":"Element is not of type \" + typeof(Image)","messagePattern":"Element is not of type \" \\+ typeof\\(Image\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/FastRenderers/ImageRenderer.cs","lineNumber":126,"sourceCode":"\t\tSizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)\n\t\t{\n\t\t\tif (_disposed)\n\t\t\t{\n\t\t\t\treturn new SizeRequest();\n\t\t\t}\n\n\t\t\tMeasure(widthConstraint, heightConstraint);\n\t\t\treturn new SizeRequest(new Size(MeasuredWidth, MeasuredHeight), MinimumSize());\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetElement(VisualElement element)\n\t\t{\n\t\t\tif (element == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(element));\n\n\t\t\tvar image = element as Image;\n\t\t\tif (image == null)\n\t\t\t\tthrow new ArgumentException(\"Element is not of type \" + typeof(Image), nameof(element));\n\n\t\t\tImage oldElement = _element;\n\t\t\t_element = image;\n\n\t\t\tPerformance.Start(out string reference);\n\n\t\t\tif (oldElement != null)\n\t\t\t\toldElement.PropertyChanged -= OnElementPropertyChanged;\n\n\t\t\telement.PropertyChanged += OnElementPropertyChanged;\n\n\t\t\tif (_visualElementTracker == null)\n\t\t\t{\n\t\t\t\t_visualElementTracker = new VisualElementTracker(this);\n\t\t\t}\n\n\t\t\tif (_visualElementRenderer == null)\n\t\t\t{","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/FastRenderers/ImageRenderer.cs#L108-L144","documentation":"ImageRenderer.SetElement explicitly rejects null with ArgumentNullException, then uses `as Image` and throws ArgumentException if the element is not an Image. The message is built by string concatenation (`\"Element is not of type \" + typeof(Image)`), so the message text is 'Element is not of type Microsoft.Maui.Controls.Image'.","triggerScenarios":"SetElement called with a non-Image VisualElement. Commonly a mis-registered ExportRenderer attribute or a manual renderer reuse.","commonSituations":"Custom ImageRenderer subclass paired with a non-Image control in the ExportRenderer attribute; migration from a different image control without updating the registration; handler dispatch routing the wrong renderer.","solutions":["Verify ExportRenderer(typeof(Image), typeof(ImageRenderer)) (or subclass) matches.","Do not reuse ImageRenderer for unrelated controls.","If supporting a derived Image type, ensure the type genuinely inherits Image so `is Image` succeeds."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(ImageButton), typeof(CustomImageRenderer))]\n// after\n[assembly: ExportRenderer(typeof(Image), typeof(CustomImageRenderer))]","handlingStrategy":"validation","validationCode":"if (element is null) throw new ArgumentNullException(nameof(element));\nif (element is not Image) throw new ArgumentException(\"Expected Image.\", nameof(element));\n((IVisualElementRenderer)renderer).SetElement(element);","typeGuard":"static bool IsImage(VisualElement e) => e is Image;","tryCatchPattern":null,"preventionTips":["Confirm ExportRenderer(typeof(Image), ...).","Don't route ImageButton or other image-like controls to ImageRenderer.","Null-check externally since the message does not distinguish null."],"tags":["android","renderer","type-mismatch","image","fast-renderer","maui-compat"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}