{"record":{"id":"87332c34f4be935b","repo":"dotnet/maui","slug":"oldelement","errorCode":null,"errorMessage":"oldElement","messagePattern":"oldElement","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/RendererPool.cs","lineNumber":27,"sourceCode":"#endif\n{\n\t[System.Obsolete]\n\tpublic sealed class RendererPool\n\t{\n\t\treadonly Dictionary<Type, Stack<IVisualElementRenderer>> _freeRenderers =\n\t\t\tnew Dictionary<Type, Stack<IVisualElementRenderer>>();\n\n\t\treadonly VisualElement _oldElement;\n\n\t\treadonly IVisualElementRenderer _parent;\n\n\t\tpublic RendererPool(IVisualElementRenderer renderer, VisualElement oldElement)\n\t\t{\n\t\t\tif (renderer == null)\n\t\t\t\tthrow new ArgumentNullException(\"renderer\");\n\n\t\t\tif (oldElement == null)\n\t\t\t\tthrow new ArgumentNullException(\"oldElement\");\n\n\t\t\t_oldElement = oldElement;\n\t\t\t_parent = renderer;\n\t\t}\n\n\t\tpublic IVisualElementRenderer GetFreeRenderer(VisualElement view)\n\t\t{\n\t\t\tif (view == null)\n\t\t\t\tthrow new ArgumentNullException(\"view\");\n\n\t\t\tvar rendererType = Controls.Internals.Registrar.Registered.GetHandlerTypeForObject(view) ?? typeof(ViewRenderer);\n\n\t\t\tStack<IVisualElementRenderer> renderers;\n\t\t\tif (!_freeRenderers.TryGetValue(rendererType, out renderers) || renderers.Count == 0)\n\t\t\t\treturn null;\n\n\t\t\tvar renderer = renderers.Pop();\n\t\t\trenderer.SetElement(view);","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/RendererPool.cs#L9-L45","documentation":"RendererPool is an obsolete (decorated with [System.Obsolete]) pool that recycles iOS child renderers when a parent VisualElement's element is swapped. Its constructor requires both a non-null renderer and a non-null oldElement; oldElement is later dereferenced as _oldElement in UpdateNewElement (line 56: ((IElementController)_oldElement).LogicalChildren). Passing null for oldElement would cause a NullReferenceException deep inside the swap logic, so the constructor fails fast with ArgumentNullException instead.","triggerScenarios":"Constructing a new RendererPool(renderer, oldElement) where oldElement is null. This typically happens when a container renderer is initialised before its old element reference has been resolved, or when a caller passes the result of a GetRenderer() lookup that returned null.","commonSituations":"Migrating away from the Compatibility layer to the new MAUI handlers; custom renderers that manage their own pool; scenarios where the element is detached/disposed between the lookup and pool construction.","solutions":["Ensure the VisualElement you pass as oldElement is non-null before constructing the pool (guard with 'if (oldElement == null) return;' or supply the parent's current Element).","Avoid RendererPool entirely - it is marked [Obsolete]; prefer the modern MAUI handler/redirector pattern for renderer recycling.","If you subclass a renderer that builds a RendererPool, check that base.Element is set before calling into the pool path."],"exampleFix":"// before\nvar pool = new RendererPool(this, _oldElementReference); // _oldElementReference may be null\n\n// after\nif (_oldElementReference == null) return;\nvar pool = new RendererPool(this, _oldElementReference);","handlingStrategy":"validation","validationCode":"if (oldElement == null) throw new ArgumentNullException(nameof(oldElement));\n// or simply skip pool creation:\nif (oldElement == null || renderer == null) return;\nvar pool = new RendererPool(renderer, oldElement);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat RendererPool as obsolete; prefer MAUI handlers.","Null-check both constructor arguments before instantiating.","Ensure the parent renderer's Element is attached before building a pool."],"tags":["argumentnullexception","ios","renderer-pool","compatibility","obsolete"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}