stride3d/stride · error · ArgumentException

The parameter of the ConvertBack method of this converter…

Error message

The parameter of the ConvertBack method of this converter must be a an instance of the Size structure.

What it means

NumericToSize.ConvertBack requires both the value and the ConverterParameter to be System.Windows.Size instances; the parameter supplies the reference size used to recover the scalar (value.Width / parameter.Width). If parameter is not a Size this ArgumentException is thrown. It mirrors the Convert-side parameter check but for the ConvertBack path.

Solutions

  1. Provide the parameter as a Size via ConverterParameter="{sd:Size w, h}"
  2. Ensure both value and parameter are Size instances before ConvertBack runs
  3. Switch to OneWay mode if ConvertBack is not actually needed
  4. Pass a real Size struct when calling ConvertBack from code/tests

Example fix

// before
Converter="{sd:NumericToSize}" ConverterParameter="10,20" Mode="TwoWay"
// after
Converter="{sd:NumericToSize}" ConverterParameter="{sd:Size 10,20}" Mode="TwoWay"
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

bool IsSizePair(object v, object p) => v is System.Windows.Size && p is System.Windows.Size;

Try / catch

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

Prevention

When it happens

Trigger: Calling ConvertBack with parameter = null, a string like "10,20", or a numeric; using the converter in TwoWay mode without the {sd:Size} markup-extension parameter.

Common situations: Two-way bindings where the ConverterParameter was authored as a plain string; forgetting to update the parameter when switching the binding to TwoWay; programmatic tests calling ConvertBack with primitive parameters.

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/8ba222564240b888. Report an issue: GitHub.

Appendix: source

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

            {
                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;
            }

            return System.Convert.ChangeType(scalar, targetType);
        }
    }
}

View on GitHub (pinned to 96fad776d2)