{"record":{"id":"5e836b22ebaa21cf","repo":"dotnet/maui","slug":"self","errorCode":null,"errorMessage":"self","messagePattern":"self","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Windows/VisualElementExtensions.cs","lineNumber":13,"sourceCode":"using System;\nusing Microsoft.Maui.Controls.Platform;\nusing Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;\n\nnamespace Microsoft.Maui.Controls.Compatibility.Platform.UWP\n{\n\t[Obsolete]\n\tpublic static class VisualElementExtensions\n\t{\n\t\tpublic static IVisualElementRenderer GetOrCreateRenderer(this VisualElement self)\n\t\t{\n\t\t\tif (self == null)\n\t\t\t\tthrow new ArgumentNullException(\"self\");\n\n\t\t\tIVisualElementRenderer renderer = Platform.GetRenderer(self);\n\t\t\tif (renderer == null)\n\t\t\t{\n\t\t\t\trenderer = Platform.CreateRenderer(self);\n\t\t\t\tPlatform.SetRenderer(self, renderer);\n\t\t\t}\n\n\t\t\treturn renderer;\n\t\t}\n\n\t\tinternal static void Cleanup(this VisualElement self)\n\t\t{\n\t\t\tif (self == null)\n\t\t\t\tthrow new ArgumentNullException(\"self\");\n\n\t\t\tIVisualElementRenderer renderer = Platform.GetRenderer(self);\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Windows/VisualElementExtensions.cs#L1-L31","documentation":"VisualElementExtensions.GetOrCreateRenderer is an extension method that throws ArgumentNullException when self (the VisualElement) is null. It retrieves or creates a platform renderer for the element via Platform.GetRenderer/CreateRenderer.","triggerScenarios":"Calling GetOrCreateRenderer() on a null VisualElement reference — e.g. a page or view that was never initialized, disposed, or nulled out before the call.","commonSituations":"View reference set to null during lifecycle teardown but renderer accessed afterward; page property not yet initialized when accessed; null-coalescing chain that unexpectedly yields null.","solutions":["Null-check the VisualElement before calling GetOrCreateRenderer()","Ensure the element is constructed and not disposed before renderer access","Use defensive programming in lifecycle-critical code paths"],"exampleFix":"// before\nIVisualElementRenderer renderer = myView.GetOrCreateRenderer(); // throws if myView is null\n\n// after\nif (myView == null)\n    throw new InvalidOperationException(nameof(myView) + \" must not be null\");\nIVisualElementRenderer renderer = myView.GetOrCreateRenderer();","handlingStrategy":"validation","validationCode":"// Before calling GetOrCreateRenderer, null-check\nif (self == null)\n    throw new ArgumentNullException(nameof(self));\nvar renderer = self.GetOrCreateRenderer();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check VisualElement references before calling extension methods","Use nullable reference types (C# 8+) to catch nulls at compile time","Guard renderer access in lifecycle-critical code"],"tags":["null-argument","extensions","validation","winui","rendering"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}