dotnet/maui · error · ArgumentNullException
renderer
Error message
renderer
What it means
ApplyNativeImageAsync is an extension method on IVisualElementRenderer used by renderers (e.g. SearchHandler, image buttons) to load a NativeImage for a BindableProperty. It dereferences renderer.NativeView and renderer.Element (lines 314-316), so a null renderer is rejected immediately. This overload delegates element resolution to 'bindable ?? renderer.Element'.
Source
Thrown at src/Compatibility/Core/src/iOS/Renderers/ImageElementManager.cs:305
{
Forms.MauiContext?.CreateLogger<ImageRenderer>()?.LogWarning("Image load cancelled");
}
catch (Exception ex)
{
Forms.MauiContext?.CreateLogger<ImageRenderer>()?.LogWarning(ex, "Image load failed");
}
return null;
}
internal static Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
{
return renderer.ApplyNativeImageAsync(null, imageSourceProperty, onSet, onLoading, cancellationToken);
}
internal static async Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableObject bindable, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
{
_ = renderer ?? throw new ArgumentNullException(nameof(renderer));
_ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));
_ = onSet ?? throw new ArgumentNullException(nameof(onSet));
// TODO: it might be good to make sure the renderer has not been disposed
// makse sure things are good before we start
var element = bindable ?? renderer.Element;
var nativeRenderer = renderer as IVisualNativeElementRenderer;
if (element == null || renderer.NativeView == null || (nativeRenderer != null && nativeRenderer.Control == null))
return;
onLoading?.Invoke(true);
if (element.GetValue(imageSourceProperty) is ImageSource initialSource && !initialSource.IsEmpty)
{
try
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Resolve the renderer via Platform.GetRenderer and null-check before calling the extension.
- Ensure the element has a live renderer (attached to platform) before initiating image loads.
- Prefer the BindableObject overload (error 247) when you only have the element, not a renderer.
Example fix
// before
renderer.ApplyNativeImageAsync(MyImageSourceProperty, img => Control.Image = img);
// after
if (renderer?.NativeView != null)
renderer.ApplyNativeImageAsync(MyImageSourceProperty, img => Control.Image = img); Defensive patterns
Strategy: validation
Validate before calling
var r = Platform.GetRenderer(element) as IVisualElementRenderer; if (r?.NativeView == null) return; r.ApplyNativeImageAsync(prop, onSet);
Prevention
- Always resolve and null-check the renderer before calling the extension.
- Use the BindableObject overload when no renderer is available.
When it happens
Trigger: Calling renderer.ApplyNativeImageAsync(...) where the renderer expression evaluates to null (e.g. Platform.GetRenderer(el) returned null), or calling the extension on a null receiver via the static-call syntax.
Common situations: Renderer lookup returns null because the element has no registered renderer yet; calling ApplyNativeImageAsync during an unload event.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/9990feddda31650f.
Report an issue: GitHub.