{"record":{"id":"a12e68a718c267b6","repo":"dotnet/maui","slug":"newelement","errorCode":null,"errorMessage":"newElement","messagePattern":"newElement","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs","lineNumber":169,"sourceCode":"\t\t\t\t\tmeasured = nativeViewMeasurable.Measure(availableWidth, availableHeight).ToDP();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmeasured = Measure(widthConstraint, heightConstraint);\n\t\t\t\t}\n\n\t\t\t\treturn new SizeRequest(measured, MinimumSize());\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Sets the element associated with this renderer.\n\t\t/// </summary>\n\t\tpublic void SetElement(TElement newElement)\n\t\t{\n\t\t\tif (newElement == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(nameof(newElement));\n\t\t\t}\n\n\t\t\tTElement oldElement = Element;\n\n\t\t\tElement = newElement;\n\n\t\t\tif (oldElement != null)\n\t\t\t{\n\t\t\t\tPlatform.SetRenderer(oldElement, null);\n\t\t\t}\n\n\t\t\t// send notification\n\t\t\tOnElementChanged(new ElementChangedEventArgs<TElement>(oldElement, newElement));\n\n\t\t\t// store renderer for the new element\n\t\t\tPlatform.SetRenderer(newElement, this);\n\n\t\t\t// add children","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs#L151-L187","documentation":"Tizen's VisualElementRenderer.SetElement throws ArgumentNullException(nameof(newElement)) when a null element is passed. SetElement binds a platform renderer to a Xamarin/Maui VisualElement and drives the renderer swap lifecycle, so a null element aborts it before any native view is attached.","triggerScenarios":"Calling SetElement(null) directly on a VisualElementRenderer<TElement>, or the platform's renderer-recycling path (Platform.SetRenderer / registrar) handing null when swapping renderers during page navigation or element reparenting.","commonSituations":"Custom Tizen renderer that calls SetElement before the Element is constructed; page recycled by the platform with a stale reference; binding context cleared mid-lifecycle leaving Element null; manual renderer instantiation that skips element wiring.","solutions":["Null-check the element before calling SetElement: if (element == null) return;","Ensure the Forms Element is fully constructed (its RealParent is set) before invoking the renderer swap.","If reusing a renderer, call Dispose/null its Element through Platform.SetRenderer(old, null) first, then SetElement(newElement) with a non-null instance.","Audit custom renderers overriding SetElement to ensure they forward a non-null TElement to base."],"exampleFix":"// before\nvar renderer = new CustomRenderer();\nrenderer.SetElement(element); // element may be null\n\n// after\nif (element != null)\n{\n    renderer.SetElement(element);\n}","handlingStrategy":"validation","validationCode":"if (newElement == null) return; // or throw a domain-specific error\nrenderer.SetElement(newElement);","typeGuard":"static bool IsValidElement(VisualElement e) => e != null && e.RealParent != null;","tryCatchPattern":"try { renderer.SetElement(element); }\ncatch (ArgumentNullException ex) when (ex.ParamName == nameof(element))\n{\n    // log and recover; element was unexpectedly null\n}","preventionTips":["Always construct the Forms Element before creating/swapping its renderer.","In custom renderers, override SetElement(TElement) and forward to base only for non-null values.","Add a debug assertion at renderer swap entry points to catch null early."],"tags":["tizen","renderer","argumentnull","null-guard","lifecycle"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}