dotnet/maui · error · ArgumentNullException
imageSourceProperty
Error message
imageSourceProperty
What it means
Same ApplyNativeImageAsync overload requires a non-null imageSourceProperty (a BindableProperty) because it calls bindable.GetValue(imageSourceProperty) (line 322) to fetch the ImageSource. A null property would NPE inside the value lookup, so it is guarded.
Source
Thrown at src/Compatibility/Core/src/iOS/Renderers/ImageElementManager.cs:306
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
{
using (var drawable = await initialSource.GetNativeImageAsync(cancellationToken))View on GitHub (pinned to f377ff1c5e)
Solutions
- Verify the BindableProperty is a real declared static field (e.g. Image.SourceProperty) and not null.
- Initialise custom BindableProperty fields before any renderer that references them loads.
- Pass the strongly-typed property (Class.PropertyProperty) rather than a variable that may be null.
Example fix
// before renderer.ApplyNativeImageAsync(_maybeNullProp, onSet); // after renderer.ApplyNativeImageAsync(MyControl.ImageSourceProperty, onSet);
Defensive patterns
Strategy: validation
Validate before calling
if (imageSourceProperty == null) throw new ArgumentNullException(nameof(imageSourceProperty)); renderer.ApplyNativeImageAsync(imageSourceProperty, onSet);
Type guard
static bool IsValidBindableProperty(BindableProperty p) => p != null;
Prevention
- Reference BindableProperty fields by their concrete static name.
- Avoid reading BindableProperty fields during static initialisation.
When it happens
Trigger: Passing null as the imageSourceProperty argument - e.g. referencing a BindableProperty field that is not yet initialised, or a typo'd property name resolving to null.
Common situations: Static-initializer ordering issues where the BindableProperty is read before its containing static field is assigned; incorrect reflection-based property lookup.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/2d0e14911e8a0d67.
Report an issue: GitHub.