stride3d/stride · error · ArgumentException

The value of the ConvertBack method of this converter must…

Error message

The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.

What it means

NumericToThickness.ConvertBack derives the original scalar by dividing a Thickness value by a Thickness parameter. It validates that value is a System.Windows.Thickness and throws this ArgumentException otherwise, preventing two-way bindings with mismatched target types from reaching the arithmetic.

Solutions

  1. Use OneWay binding — this converter is intended for one-way display scaling
  2. Ensure the two-way target property is of type System.Windows.Thickness
  3. Attach the converter only to bindings whose target is a Thickness (e.g. Margin, BorderThickness)
  4. Perform scalar round-trip logic in the view model if two-way numeric editing is required

Example fix

// before
<Binding Path="Scale" Converter="{sd:NumericToThickness}" ConverterParameter="{sd:Thickness 5}" Mode="TwoWay"/>
// after
<Binding Path="Scale" Converter="{sd:NumericToThickness}" ConverterParameter="{sd:Thickness 5}" Mode="OneWay"/>
Defensive patterns

Strategy: validation

Validate before calling

bool CanConvertBack(object value) => value is System.Windows.Thickness;

Type guard

bool IsThickness(object v) => v is System.Windows.Thickness;

Try / catch

try
{
    return converter.ConvertBack(value, typeof(double), thicknessParameter, culture);
}
catch (ArgumentException)
{
    return Binding.DoNothing;
}

Prevention

When it happens

Trigger: ConvertBack invoked with value = null, a double, string, or Size because the binding's target property is not a Thickness while the converter is used in TwoWay mode.

Common situations: Two-way binding on a non-Thickness property (e.g. a double Slider value) with NumericToThickness attached; copy-pasted bindings from a Thickness-targeted control to a numeric one; programmatic ConvertBack calls in tests with wrong types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToThickness.cs:49

                throw new ArgumentException("The value of this converter must be convertible to a double.", exception);
            }

            if (!(parameter is Thickness))
            {
                throw new ArgumentException("The parameter of this converter must be an instance of the Thickness structure. Use {sd:Thickness (arguments)} to construct one.");
            }

            var thickness = (Thickness)parameter;
            var result = new Thickness(thickness.Left * scalar, thickness.Top * scalar, thickness.Right * scalar, thickness.Bottom * scalar);
            return result;
        }

        /// <inheritdoc/>
        public override object ConvertBack(object value, [NotNull] Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is Thickness))
            {
                throw new ArgumentException("The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
            }
            if (!(parameter is Thickness))
            {
                throw new ArgumentException("The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
            }
            var thicknessValue = (Thickness)value;
            var thicknessParameter = (Thickness)parameter;

            var scalar = 0.0;
            if (Math.Abs(thicknessParameter.Left) > double.Epsilon)
            {
                scalar = thicknessValue.Left / thicknessParameter.Left;
            }
            else if (Math.Abs(thicknessParameter.Right) > double.Epsilon)
            {
                scalar = thicknessValue.Right / thicknessParameter.Right;
            }
            else if (Math.Abs(thicknessParameter.Top) > double.Epsilon)

View on GitHub (pinned to 96fad776d2)