stride3d/stride · error · ArgumentNullException

Value cannot be null. (Parameter 'property')

Error message

Value cannot be null. (Parameter 'property')

What it means

DeepSetValue requires both a source DependencyObject and a DependencyProperty to set. It validates the property is non-null and throws ArgumentNullException with parameter name 'property', since DependencyProperty.SetValue would fail without a valid property identifier.

Solutions

  1. Pass the correct static DependencyProperty field (e.g. TextBlock.TextProperty).
  2. Null-check the resolved property before calling DeepSetValue.
  3. Verify the property exists on the target control type before reflection-resolving it.

Example fix

// before
var prop = typeof(TextBlock).GetField("TextProp")?.GetValue(null) as DependencyProperty; // null
root.DeepSetValue(prop, value);
// after
var prop = typeof(TextBlock).GetField("TextProperty")?.GetValue(null) as DependencyProperty;
if (prop != null)
    root.DeepSetValue(prop, value);
Defensive patterns

Strategy: type-guard

Validate before calling

if (prop == null) throw new InvalidOperationException("DependencyProperty must be resolved before DeepSetValue");

Type guard

bool CanDeepSet(DependencyObject source, DependencyProperty prop) => source != null && prop != null;

Try / catch

try { root.DeepSetValue(prop, value); } catch (ArgumentNullException ex) when (ex.ParamName == "property") { /* resolve property by name, log */ }

Prevention

When it happens

Trigger: Calling DeepSetValue with a null DependencyProperty, e.g. a static field lookup (Control.FontSizeProperty) that was misnamed or the property was resolved dynamically and returned null.

Common situations: Reflection lookup of a *Property field returning null; copy-paste from a different control type; refactoring renamed the property field.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f06c780dce053054. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Extensions/DependencyObjectExtensions.cs:50

                flags |= BindingFlags.FlattenHierarchy;

            return source.DependencyObjectType.SystemType.GetFields(flags)
                .Where(fi => fi.MemberType == MemberTypes.Field && fi.FieldType == dependencyPropertyType)
                .Select(fi => (DependencyProperty)fi.GetValue(source))
                .OrderBy(dp => dp.Name)
                .ToArray();
        }

        /// <summary>
        /// Sets the value of a DependencyProperty on a DependencyObject and all its logical children.
        /// </summary>
        /// <param name="source">Root DependencyObject of which to set the DependencyProperty value.</param>
        /// <param name="property">DependencyProperty to set.</param>
        /// <param name="value">Value to set.</param>
        public static void DeepSetValue([NotNull] this DependencyObject source, [NotNull] DependencyProperty property, object value)
        {
            if (source == null) throw new ArgumentNullException(nameof(source));
            if (property == null) throw new ArgumentNullException(nameof(property));

            source.SetValue(property, value);
            foreach (object child in LogicalTreeHelper.GetChildren(source as dynamic))
            {
                var depChild = child as DependencyObject;
                depChild?.DeepSetValue(property, value);
            }
        }

        /// <summary>
        /// Find the root parent, along the visual tree.
        /// </summary>
        /// <param name="source">Base node from where to start looking for root.</param>
        /// <returns>Returns the retrieved root, or null otherwise.</returns>
        [CanBeNull]
        public static Visual FindVisualRoot([NotNull] this DependencyObject source)
        {
            if (source == null) throw new ArgumentNullException(nameof(source));

View on GitHub (pinned to 96fad776d2)