stride3d/stride · error · InvalidOperationException

The value of the property

Error message

The value of the property '{e.Property.Name}' cannot be different from the value '{metadata.DefaultValue}'

What it means

NumericTextBox registers OnForbiddenPropertyChanged on certain dependency properties (e.g. readonly/format-related) whose value must never change from the metadata default. Setting such a property to any other value in XAML or code raises this InvalidOperationException immediately.

Solutions

  1. Remove the property setter/binding that changes the forbidden property, or set it back to its default value
  2. Find which property via e.Property in the stack/message and check whether it is legitimately settable on this control
  3. Set the property on an inner element of your template instead of on NumericTextBox itself
  4. If you own the control, move the property to the list of settable ones rather than marking it forbidden

Example fix

<!-- before -->
<Style TargetType="ntb:NumericTextBox">
  <Setter Property="IsReadOnly" Value="True"/>
</Style>
<!-- after: apply the behavior where it is supported -->
<Style TargetType="ntb:NumericTextBox">
  <!-- remove the forbidden setter -->
  <Setter Property="Background" Value="LightYellow"/>
</Style>
Defensive patterns

Strategy: validation

Validate before calling

// verify a forbidden property is at its default before setting style
var meta = NumericTextBox.IsReadOnlyProperty.GetMetadata(typeof(NumericTextBox));
if (!Equals(newValue, meta.DefaultValue)) throw new InvalidOperationException($"{nameof(NumericTextBox.IsReadOnly)} cannot differ from default {meta.DefaultValue}");

Try / catch

try { ApplyStyle(); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("The value of the property")) { log.Error(ex, "Style sets a forbidden property on NumericTextBox"); throw; }

Prevention

When it happens

Trigger: Assigning a local value, style setter, binding, or animation to a forbidden DP of NumericTextBox (any value different from its DefaultMetadata DefaultValue).

Common situations: Setting properties like IsReadOnly/allow-drop style flags in a Style targeting NumericTextBox; copy-pasted setters from a parent type; XAML designers emitting explicit values that differ from defaults.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Controls/NumericTextBox.cs:562

        }

        private static void OnSmallDecreaseCommand([NotNull] object sender, ExecutedRoutedEventArgs e)
        {
            UpdateValueCommand(sender, x => (x.Value ?? x.Maximum) - x.SmallChange);
        }

        private static void OnResetValueCommand([NotNull] object sender, ExecutedRoutedEventArgs e)
        {
            UpdateValueCommand(sender, x => 0.0, false);
        }

        private static void OnForbiddenPropertyChanged([NotNull] DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var metadata = e.Property.GetMetadata(d);
            if (!Equals(e.NewValue, metadata.DefaultValue))
            {
                var message = $"The value of the property '{e.Property.Name}' cannot be different from the value '{metadata.DefaultValue}'";
                throw new InvalidOperationException(message);
            }
        }
    }
}

View on GitHub (pinned to 96fad776d2)