{"record":{"id":"2d0e14911e8a0d67","repo":"dotnet/maui","slug":"imagesourceproperty","errorCode":null,"errorMessage":"imageSourceProperty","messagePattern":"imageSourceProperty","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Renderers/ImageElementManager.cs","lineNumber":306,"sourceCode":"\t\t\t\tForms.MauiContext?.CreateLogger<ImageRenderer>()?.LogWarning(\"Image load cancelled\");\n\t\t\t}\n\t\t\tcatch (Exception ex)\n\t\t\t{\n\t\t\t\tForms.MauiContext?.CreateLogger<ImageRenderer>()?.LogWarning(ex, \"Image load failed\");\n\t\t\t}\n\n\t\t\treturn null;\n\t\t}\n\n\t\tinternal static Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))\n\t\t{\n\t\t\treturn renderer.ApplyNativeImageAsync(null, imageSourceProperty, onSet, onLoading, cancellationToken);\n\t\t}\n\n\t\tinternal static async Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableObject bindable, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))\n\t\t{\n\t\t\t_ = renderer ?? throw new ArgumentNullException(nameof(renderer));\n\t\t\t_ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));\n\t\t\t_ = onSet ?? throw new ArgumentNullException(nameof(onSet));\n\n\t\t\t// TODO: it might be good to make sure the renderer has not been disposed\n\n\t\t\t// makse sure things are good before we start\n\t\t\tvar element = bindable ?? renderer.Element;\n\n\t\t\tvar nativeRenderer = renderer as IVisualNativeElementRenderer;\n\n\t\t\tif (element == null || renderer.NativeView == null || (nativeRenderer != null && nativeRenderer.Control == null))\n\t\t\t\treturn;\n\n\t\t\tonLoading?.Invoke(true);\n\t\t\tif (element.GetValue(imageSourceProperty) is ImageSource initialSource && !initialSource.IsEmpty)\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tusing (var drawable = await initialSource.GetNativeImageAsync(cancellationToken))","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Renderers/ImageElementManager.cs#L288-L324","documentation":"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.","triggerScenarios":"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.","commonSituations":"Static-initializer ordering issues where the BindableProperty is read before its containing static field is assigned; incorrect reflection-based property lookup.","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."],"exampleFix":"// before\nrenderer.ApplyNativeImageAsync(_maybeNullProp, onSet);\n\n// after\nrenderer.ApplyNativeImageAsync(MyControl.ImageSourceProperty, onSet);","handlingStrategy":"validation","validationCode":"if (imageSourceProperty == null) throw new ArgumentNullException(nameof(imageSourceProperty));\nrenderer.ApplyNativeImageAsync(imageSourceProperty, onSet);","typeGuard":"static bool IsValidBindableProperty(BindableProperty p) => p != null;","tryCatchPattern":null,"preventionTips":["Reference BindableProperty fields by their concrete static name.","Avoid reading BindableProperty fields during static initialisation."],"tags":["argumentnullexception","ios","image","bindableproperty","static-init"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}