{"record":{"id":"434c96139081e0b2","repo":"stride3d/stride","slug":"invalid-uri-argument","errorCode":null,"errorMessage":"Invalid 'uri' argument.","messagePattern":"Invalid 'uri' argument\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Extensions/ImageExtensions.cs","lineNumber":27,"sourceCode":"\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)\n                throw new ArgumentNullException(nameof(uri));\n\n            var source = new BitmapImage();\n            source.BeginInit();\n            source.UriSource = uri;\n            source.CacheOption = BitmapCacheOption.OnLoad;\n            source.EndInit();\n\n            return source;\n        }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Extensions/ImageExtensions.cs#L9-L45","documentation":"The string overload of ImageExtensions.SetSource throws ArgumentException(\"Invalid 'uri' argument.\") when the string is null, empty, or whitespace — a deliberate ArgumentException (not ArgumentNullException) covering the empty/whitespace case as well.","triggerScenarios":"Calling image.SetSource(\"\") or image.SetSource(\"   \") with the string overload.","commonSituations":"Binding a path property that defaults to empty string; a settings file or resource key resolved to blank; trimming user input left an empty value that is then used as an image source.","solutions":["Validate with string.IsNullOrWhiteSpace and provide a default/placeholder image instead.","Fix the configuration or resource supplying the empty path.","Guard the call site: only call SetSource when the path is non-empty.","If empty means 'no image', clear image.Source explicitly rather than calling SetSource."],"exampleFix":"// before\nlogo.SetSource(config.IconPath ?? \"\"); // throws for empty\n// after\nif (!string.IsNullOrWhiteSpace(config.IconPath))\n    logo.SetSource(config.IconPath);\nelse\n    logo.Source = null;","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(imagePath))\n{\n    image.Source = null; // or placeholder\n    return;\n}\nimage.SetSource(imagePath);","typeGuard":"static bool IsValidImageUri(string uri) => Uri.TryCreate(uri, UriKind.Absolute, out _);","tryCatchPattern":"try { image.SetSource(imagePath); }\ncatch (ArgumentException) { image.Source = placeholderImage; }","preventionTips":["Use string.IsNullOrWhiteSpace as the guard, not just null check","Provide fallback/placeholder assets for missing images","Trim and validate user-supplied paths before use"],"tags":["wpf","argumentexception","image","uri"],"backgroundTag":"invalid-argument-value","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"}