dotnet/maui · error · ArgumentNullException
renderer
Error message
renderer
What it means
EventTracker constructor throws ArgumentNullException(nameof(renderer)) when the IVisualElementRenderer is null. EventTracker attaches gesture-recognizer collection-changed handling to a renderer's element; without a renderer there is no element to track, so construction is rejected immediately.
Source
Thrown at src/Compatibility/Core/src/iOS/EventTracker.cs:49
readonly NotifyCollectionChangedEventHandler _collectionChangedHandler;
readonly Dictionary<IGestureRecognizer, NativeGestureRecognizer> _gestureRecognizers = new Dictionary<IGestureRecognizer, NativeGestureRecognizer>();
readonly IVisualElementRenderer _renderer;
bool _disposed;
NativeView _handler;
double _previousScale = 1.0;
#if __MOBILE__
UITouchEventArgs _shouldReceiveTouch;
DragAndDropDelegate _dragAndDropDelegate;
#endif
public EventTracker(IVisualElementRenderer renderer)
{
if (renderer == null)
throw new ArgumentNullException(nameof(renderer));
_collectionChangedHandler = ModelGestureRecognizersOnCollectionChanged;
_renderer = renderer;
_renderer.ElementChanged += OnElementChanged;
}
ObservableCollection<IGestureRecognizer> ElementGestureRecognizers
{
get
{
return ((_renderer?.Element as IGestureController)
?.CompositeGestureRecognizers as ObservableCollection<IGestureRecognizer>);
}
}
internal void Disconnect()
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Create EventTracker only after the renderer is fully initialized and assigned.
- Verify the renderer is non-null before constructing EventTracker.
- Move EventTracker initialization to OnElementChanged / the ElementChanged event.
Example fix
// before
_tracker = new EventTracker(null);
// after
if (renderer == null)
throw new InvalidOperationException("Renderer not ready.");
_tracker = new EventTracker(renderer); Defensive patterns
Strategy: validation
Validate before calling
if (renderer == null)
throw new InvalidOperationException("Renderer is not ready; cannot create EventTracker.");
var tracker = new EventTracker(renderer); Type guard
static bool IsRendererReady(IVisualElementRenderer r) => r?.Element != null;
Prevention
- Construct EventTracker after the renderer is initialized.
- Move EventTracker setup to OnElementChanged.
- Null-check the renderer before construction.
When it happens
Trigger: Constructing EventTracker with a null renderer; typically only inside custom renderers that build an EventTracker before Platform.GetRenderer returns a value.
Common situations: A custom renderer instantiating EventTracker during constructor execution before the renderer is fully initialized; passing renderer from a GetRenderer call that returned null because the element was not registered.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/c793be0c583c4bc4.
Report an issue: GitHub.