{"record":{"id":"5344f8b2480a7bfe","repo":"dotnet/maui","slug":"renderer-5344f8","errorCode":null,"errorMessage":"renderer","messagePattern":"renderer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/VisualElementTracker.cs","lineNumber":48,"sourceCode":"\t\tVisualElement _element;\n\n\t\t// Track these by hand because the calls down into iOS are too expensive\n\t\tbool _isInteractive;\n\t\tRect _lastBounds;\n#if !__MOBILE__\n\t\tRect _lastParentBounds;\n#endif\n\t\tCALayer _layer;\n\t\tCGPoint _originalAnchor;\n\t\tint _updateCount;\n\n\t\tpublic VisualElementTracker(IVisualElementRenderer renderer) : this(renderer, true)\n\t\t{\n\t\t}\n\n\t\tpublic VisualElementTracker(IVisualElementRenderer renderer, bool trackFrame)\n\t\t{\n\t\t\tRenderer = renderer ?? throw new ArgumentNullException(\"renderer\");\n\n\t\t\t_propertyChangedHandler = HandlePropertyChanged;\n\t\t\t_sizeChangedEventHandler = HandleSizeChanged;\n\t\t\t_batchCommittedHandler = HandleRedrawNeeded;\n\n\t\t\tTrackFrame = trackFrame;\n\t\t\trenderer.ElementChanged += OnRendererElementChanged;\n\t\t\tSetElement(null, renderer.Element);\n\t\t}\n\n\t\tbool TrackFrame { get; set; }\n\n\t\tIVisualElementRenderer Renderer { get; set; }\n\n\t\tpublic void Dispose()\n\t\t{\n\t\t\tDispose(true);\n\t\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/VisualElementTracker.cs#L30-L66","documentation":"VisualElementTracker is the iOS-specific component that tracks a VisualElement's property changes and applies them to the native CALayer. Its constructor requires a non-null IVisualElementRenderer because it immediately subscribes to ElementChanged events and reads renderer.Element. Passing null would cause a NullReferenceException on every subsequent operation, so the constructor fails fast with ArgumentNullException.","triggerScenarios":"Constructing `new VisualElementTracker(null)` or `new VisualElementTracker(null, trackFrame: false)` from a custom renderer whose IVisualElementRenderer field has not yet been assigned. Also occurs when a renderer subclass calls base tracker construction during partial initialization.","commonSituations":"Custom iOS renderers that instantiate VisualElementTracker in a field initializer or constructor before the renderer itself is fully wired. DI or factory patterns that return null renderers. Refactoring a renderer and forgetting to pass `this`.","solutions":["Ensure the IVisualElementRenderer instance is fully constructed before creating the tracker — pass `this` from within the renderer's own constructor or lifecycle method.","Add a null guard at the call site: `if (renderer != null) _tracker = new VisualElementTracker(renderer);`","If using a factory or DI container, verify the renderer registration returns a non-null instance before passing it to the tracker constructor."],"exampleFix":"// before\n_tracker = new VisualElementTracker(someFieldThatMightBeNull);\n\n// after\n_tracker = new VisualElementTracker(this); // pass the fully-constructed renderer","handlingStrategy":"validation","validationCode":"if (renderer is null)\n    throw new InvalidOperationException(\"Cannot create VisualElementTracker: renderer is not initialized.\");\nvar tracker = new VisualElementTracker(renderer);","typeGuard":"// Ensure the renderer is non-null and implements IVisualElementRenderer before construction\nstatic bool IsValidRenderer(object? renderer)\n    => renderer is IVisualElementRenderer;","tryCatchPattern":null,"preventionTips":["Always pass `this` (the fully-constructed renderer) when creating a VisualElementTracker inside a renderer class.","Avoid field initializers that create trackers before the renderer is constructed.","Use nullable reference types to catch null renderer assignments at compile time."],"tags":["maui","ios","renderer","argument-null","visual-element-tracker"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}