stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'uri')
Error message
Value cannot be null. (Parameter 'uri')
What it means
ImageExtensions.SetSource(this Image, string) delegates to the Uri overload after converting the string, and throws ArgumentNullException when the uri string is null. The null check for uri precedes the conversion to a Uri object.
Solutions
- Check string.IsNullOrWhiteSpace before calling SetSource and skip or use a placeholder image.
- Initialize the bound path property to a valid default URI.
- Fix the upstream data source so the image path is never null.
- Coalesce to a fallback asset: SetSource(uri ?? DefaultImageUri).
Example fix
// before
logo.SetSource(item.ImagePath); // ImagePath may be null
// after
if (!string.IsNullOrWhiteSpace(item.ImagePath))
logo.SetSource(item.ImagePath); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(imagePath))
image.SetSource(imagePath); Type guard
static bool HasImageSource(string path) => !string.IsNullOrWhiteSpace(path);
Try / catch
try { image.SetSource(imagePath); }
catch (ArgumentNullException) { image.Source = null; } Prevention
- Initialize path properties to valid defaults
- Treat null path as 'no image' explicitly in view-models
- Validate configuration/resource paths at startup
When it happens
Trigger: Calling image.SetSource(null) with a string argument, or passing a null value coming from a binding/view-model property that represents the image path.
Common situations: Bound path property is null because data context is not yet set; configuration/app-resource for the image path is missing; database or model record has a null image path field.
Related errors
- Invalid 'uri' argument.
- Value cannot be null. (Parameter 'image')
- Value cannot be null. (Parameter 'getChildFunc')
- Value cannot be null. (Parameter 'getChildrenCountFunc')
- A dependency object is already attached to this instance of…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/b8afaf7b26a79e24.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Extensions/ImageExtensions.cs:19
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Stride.Core.Annotations;
namespace Stride.Core.Presentation.Extensions
{
public static class ImageExtensions
{
public static void SetSource([NotNull] this Image image, [NotNull] Uri uri)
{
if (image == null)
throw new ArgumentNullException(nameof(image));
if (uri == null)
throw new ArgumentNullException(nameof(uri));
image.Source = ImageSourceFromFile(uri);
}
public static void SetSource([NotNull] this Image image, [NotNull] string uri)
{
if (string.IsNullOrWhiteSpace(uri))
throw new ArgumentException("Invalid 'uri' argument.");
SetSource(image, new Uri(uri));
}
[NotNull]
public static ImageSource ImageSourceFromFile([NotNull] Uri uri)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));
View on GitHub (pinned to 96fad776d2)