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 Size structure.

What it means

NumericToSize.ConvertBack reverses the scaling: it takes a Size value and a Size parameter and derives the original scalar. It validates that value is a System.Windows.Size and throws this ArgumentException otherwise. This keeps two-way bindings from receiving unconvertible values from the UI target side.

Solutions

  1. Use OneWay mode — NumericToSize is designed as a display converter; do not bind TwoWay unless the target is a Size
  2. Ensure the bound target property type is System.Windows.Size
  3. Verify the correct converter (NumericToSize vs NumericToThickness vs plain numeric) is attached
  4. If two-way numeric editing is needed, handle conversion in the view model instead

Example fix

// before
<Binding Path="Scale" Converter="{sd:NumericToSize}" ConverterParameter="{sd:Size 10,20}" Mode="TwoWay"/>
// after
<Binding Path="Scale" Converter="{sd:NumericToSize}" ConverterParameter="{sd:Size 10,20}" Mode="OneWay"/>
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

bool IsSize(object v) => v is System.Windows.Size;

Try / catch

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

Prevention

When it happens

Trigger: A two-way MultiBinding/Binding where the target-side value handed to ConvertBack is not a Size — e.g. the target property is a double, string, or Thickness and the converter is used in TwoWay mode.

Common situations: Setting Binding Mode=TwoWay on a property that is not of type Size; accidentally wiring NumericToSize in a binding where the control's value is a number; template reuse across differently-typed properties.

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/716cfad9713a3a6b. Report an issue: GitHub.

Appendix: source

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

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

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

            var size = (Size)parameter;
            var result = new Size(size.Width * scalar, size.Height * scalar);
            return result;
        }

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

            var scalar = 0.0;
            if (Math.Abs(sizeParameter.Width) > double.Epsilon)
            {
                scalar = sizeValue.Width / sizeParameter.Width;
            }
            else if (Math.Abs(sizeParameter.Height) > double.Epsilon)
            {
                scalar = sizeValue.Height / sizeParameter.Height;
            }

View on GitHub (pinned to 96fad776d2)