{"record":{"id":"17bc8f416c301640","repo":"dotnet/maui","slug":"self-17bc8f","errorCode":null,"errorMessage":"self","messagePattern":"self","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Extensions/VisualElementExtensions.cs","lineNumber":13,"sourceCode":"using System;\nusing Microsoft.Maui.Controls.Platform;\nusing Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;\n\nnamespace Microsoft.Maui.Controls.Compatibility.Platform.iOS\n{\n\t[System.Obsolete]\n\tpublic static class VisualElementExtensions\n\t{\n\t\tpublic static IVisualElementRenderer GetRenderer(this VisualElement self)\n\t\t{\n\t\t\tif (self == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(self));\n\n\t\t\treturn Platform.GetRenderer(self);\n\t\t}\n\t\tinternal static bool UseLegacyColorManagement<T>(this T element) where T : VisualElement, IElementConfiguration<T>\n\t\t{\n\t\t\t// Determine whether we're letting the VSM handle the colors or doing it the old way\n\t\t\t// or disabling the legacy color management and doing it the old-old (pre 2.0) way\n\t\t\treturn !element.HasVisualStateGroups()\n\t\t\t\t\t&& element.OnThisPlatform().GetIsLegacyColorModeEnabled();\n\t\t}\n\t}\n}","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Extensions/VisualElementExtensions.cs#L1-L25","documentation":"VisualElementExtensions.GetRenderer(this VisualElement self) throws ArgumentNullException(nameof(self)) when called on a null VisualElement. The extension method exists to retrieve the platform renderer and cannot operate without an element.","triggerScenarios":"Invoking GetRenderer() on a null VisualElement reference; common when a renderer/accessory accesses an Element that has not been set or has been cleared.","commonSituations":"Custom renderers calling this.GetRenderer() where `this` context has a null element; layout code operating on a recycled element; chaining extension methods on possibly-null visual elements without guarding.","solutions":["Null-check the VisualElement before calling GetRenderer().","Use Platform.GetRenderer directly if you want null-tolerant behavior.","Audit custom renderer code paths that reach GetRenderer during detachment/disposal."],"exampleFix":"// before\nvar r = element.GetRenderer();\n// after\nif (element != null)\n    var r = element.GetRenderer();","handlingStrategy":"validation","validationCode":"if (self == null) return null;\nreturn self.GetRenderer();","typeGuard":"static bool HasRenderer(VisualElement e) => e != null && Platform.GetRenderer(e) != null;","tryCatchPattern":null,"preventionTips":["Null-check VisualElement before calling GetRenderer().","Use Platform.GetRenderer directly for null-tolerant behavior.","Audit custom renderer code paths during teardown."],"tags":["maui","xamarin-forms","ios","visualelement","renderer","argument-validation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}