dotnet/maui · error · ArgumentNullException

bindable

Error message

bindable

What it means

A second ApplyNativeImageAsync overload extends BindableObject directly (no renderer needed). It calls bindable.GetValue(imageSourceProperty) (line 366), so a null bindable is rejected. Use this when you have only the element/control, not its platform renderer.

Source

Thrown at src/Compatibility/Core/src/iOS/Renderers/ImageElementManager.cs:359

				{
					if (element != null && onLoading != null)
					{
						// only mark as finished if we are still on the same image
						if (element.GetValue(imageSourceProperty) == initialSource)
							onLoading.Invoke(false);
					}
				}
			}
			else
			{
				onSet(null);
				onLoading?.Invoke(false);
			}
		}

		internal static async Task ApplyNativeImageAsync(this BindableObject bindable, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			_ = bindable ?? throw new ArgumentNullException(nameof(bindable));
			_ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));
			_ = onSet ?? throw new ArgumentNullException(nameof(onSet));

			onLoading?.Invoke(true);
			if (bindable.GetValue(imageSourceProperty) is ImageSource initialSource)
			{
				try
				{
					using (var nsimage = await initialSource.GetNativeImageAsync(cancellationToken))
					{
						// only set if we are still on the same image
						if (bindable.GetValue(imageSourceProperty) == initialSource)
							onSet(nsimage);
					}
				}
				finally
				{
					if (onLoading != null)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Capture the element in a local and null-check before awaiting the image load continuation.
  2. Use a CancellationToken tied to the element's lifecycle and cancel on unload.
  3. Prefer calling this overload on a strongly-held Element reference.

Example fix

// before
await Element.ApplyNativeImageAsync(Image.SourceProperty, onSet);
// (Element may be null after await)

// after
var el = Element;
if (el != null)
    await el.ApplyNativeImageAsync(Image.SourceProperty, onSet);
Defensive patterns

Strategy: validation

Validate before calling

var el = bindable;
if (el == null) return;
await el.ApplyNativeImageAsync(prop, onSet);

Prevention

When it happens

Trigger: Calling the extension on a null BindableObject receiver, e.g. when an element was already disposed/unparented before the async image load continued.

Common situations: Async continuation running after the page popped (element nulled out); weak-reference cleanup leaving the bindable null.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/7b439820dab84caf. Report an issue: GitHub.