{"record":{"id":"f6393ac9eb9c4d84","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-image","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'image')","messagePattern":"Value cannot be null\\. \\(Parameter 'image'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Extensions/ImageExtensions.cs","lineNumber":17,"sourceCode":"// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\n\nusing System;\nusing System.Windows.Controls;\nusing System.Windows.Media;\nusing System.Windows.Media.Imaging;\nusing Stride.Core.Annotations;\n\nnamespace Stride.Core.Presentation.Extensions\n{\n    public static class ImageExtensions\n    {\n        public static void SetSource([NotNull] this Image image, [NotNull] Uri uri)\n        {\n            if (image == null)\n                throw new ArgumentNullException(nameof(image));\n            if (uri == null)\n                throw new ArgumentNullException(nameof(uri));\n\n            image.Source = ImageSourceFromFile(uri);\n        }\n\n        public static void SetSource([NotNull] this Image image, [NotNull] string uri)\n        {\n            if (string.IsNullOrWhiteSpace(uri))\n                throw new ArgumentException(\"Invalid 'uri' argument.\");\n\n            SetSource(image, new Uri(uri));\n        }\n\n        [NotNull]\n        public static ImageSource ImageSourceFromFile([NotNull] Uri uri)\n        {\n            if (uri == null)","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Extensions/ImageExtensions.cs#L1-L35","documentation":"ImageExtensions.SetSource(this Image, Uri) assigns image.Source from a file Uri and validates both arguments, throwing ArgumentNullException when the Image control itself is null. This typically happens when the extension method is invoked on a null receiver or with a null first argument.","triggerScenarios":"Calling image.SetSource(uri) where the Image instance is null (e.g. FindName/FindResource lookup failed) — a null this on an extension method call does not throw NullReferenceException but flows into the guard.","commonSituations":"XAML control resolved by name at a point where the visual tree is not yet built; Image removed from the tree before the code runs; a view-model binding produced a null Image reference in generated/code-behind code.","solutions":["Null-check the Image before calling SetSource.","Resolve the Image after the page is loaded (Loaded event or OnApplyTemplate).","Fix the lookup returning null (verify x:Name and control presence).","Prefer setting the Source property directly with a null-safe wrapper if the image may be absent."],"exampleFix":"// before\nvar img = FindName(\"Logo\") as Image;\nimg.SetSource(new Uri(\"pack://application:,,,/logo.png\")); // NRE-free but throws ArgumentNullException inside\n// after\nvar img = FindName(\"Logo\") as Image;\nif (img != null)\n    img.SetSource(new Uri(\"pack://application:,,,/logo.png\"));","handlingStrategy":"validation","validationCode":"var img = FindName(\"Logo\") as Image;\nif (img == null) return; // or log\nimg.SetSource(new Uri(\"pack://application:,,,/logo.png\"));","typeGuard":"static bool CanSetSource(Image image, Uri uri) => image != null && uri != null;","tryCatchPattern":"try { image.SetSource(uri); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"image\") { logger.Warn(\"Image control not found; skipping source assignment\"); }","preventionTips":["Null-check controls resolved via FindName/FindResource before use","Assign image sources in Loaded/OnApplyTemplate, not constructors","Avoid storing Image references that can be collected on re-templating"],"tags":["wpf","argumentnull","image"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}