stride3d/stride · error · ArgumentException

The value of this converter must be convertible to a double.

Error message

The value of this converter must be convertible to a double.

What it means

NumericToThickness multiplies a WPF Thickness (the converter parameter) by a numeric scalar (the bound value). The scalar is produced by ConverterHelper.ConvertToDouble; a failure there is wrapped in this ArgumentException with the original exception attached as InnerException. It fails fast instead of producing a zero or degenerate Thickness.

Solutions

  1. Bind a numeric property (double/int) as the value
  2. Check InnerException for the failing value and fix its type/format
  3. Parse or normalize strings in the view model before binding
  4. Use invariant culture when converting user-entered numbers

Example fix

// before
<Binding Path="ScaleText"/> <!-- "1,5" -->
// after
<Binding Path="Scale"/> <!-- double 1.5 -->
Defensive patterns

Strategy: validation

Validate before calling

bool CanScaleThickness(object value) =>
    value is double || value is int || value is float || value is long || value is decimal ||
    (value is string s && double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out _));

Type guard

bool IsDoubleConvertible(object v) => v is double || v is int || v is float || v is long || v is decimal;

Try / catch

try
{
    return converter.Convert(value, typeof(Thickness), thicknessParameter, culture);
}
catch (ArgumentException ex)
{
    Log(ex.InnerException);
    return (Thickness)thicknessParameter; // unscaled fallback
}

Prevention

When it happens

Trigger: Convert receives a value that ConverterHelper.ConvertToDouble cannot convert: null, a non-numeric object, an unparseable string like "auto" or "10px", or a string with wrong culture decimal separators.

Common situations: Binding a string thickness/scale from user input directly; binding an enum or object property; culture mismatches where "1.5" vs "1,5" fails parsing.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

    /// A <see cref="Thickness"/> must be passed as a parameter of this converter. You can use the <see cref="MarkupExtensions.ThicknessExtension"/>
    /// markup extension to easily pass one, with the following syntax: {sd:Thickness (arguments)}. The resulting thickness will
    /// be the parameter thickness multiplied bu the scalar double value.
    /// </summary>
    [ValueConversion(typeof(double), typeof(Thickness))]
    public class NumericToThickness : ValueConverterBase<NumericToThickness>
    {
        /// <inheritdoc/>
        [NotNull]
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double scalar;
            try
            {
                scalar = ConverterHelper.ConvertToDouble(value, culture);
            }
            catch (Exception exception)
            {
                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.");

View on GitHub (pinned to 96fad776d2)