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

Multiply.Convert multiplies a value by a parameter, both of which must be convertible to double via ConverterHelper.ConvertToDouble. If the value cannot be converted (wrong type, unparsable string), the original exception is wrapped in an ArgumentException. This fails fast rather than producing silently wrong numeric results.

Solutions

  1. Ensure the bound value is numeric or a culture-correct numeric string.
  2. Bind to a double-typed property (e.g. expose double instead of string in the ViewModel).
  3. Use StringFormat or a preceding converter to normalize the value before Multiply.

Example fix

// before
public string Scale { get; set; } = "1.5"; // may fail on some cultures
// after
public double Scale { get; set; } = 1.5;
Defensive patterns

Strategy: type-guard

Validate before calling

bool isDoubleConvertible(object? v) => v is double || v is int || v is float || v is decimal || (v is string s && double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out _));

Type guard

static bool TryGetDouble(object? v, out double d) => double.TryParse(Convert.ToString(v, CultureInfo.InvariantCulture), NumberStyles.Any, CultureInfo.InvariantCulture, out d);

Try / catch

try { result = multiply.Convert(value, targetType, parameter, culture); } catch (ArgumentException ex) { /* show validation error; use fallback */ }

Prevention

When it happens

Trigger: Binding a non-numeric property (e.g. a string like "abc" or an object) to a Multiply converter; calling Convert with a value ConverterHelper.ConvertToDouble cannot handle.

Common situations: ViewModel property changed from double to string; binding to a Boolean property; localization issues where a string with wrong decimal separator is passed.

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/09e792a936697e60. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/Multiply.cs:27

namespace Stride.Core.Presentation.ValueConverters
{
    /// <summary>
    /// This converter will multiply a given numeric value by the numeric value given as parameter.
    /// </summary>
    [ValueConversion(typeof(double), typeof(double))]
    public class Multiply : ValueConverterBase<Multiply>
    {
        /// <inheritdoc/>
        public override object Convert(object value, [NotNull] 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);
            }

            double param;
            try
            {
                param = ConverterHelper.ConvertToDouble(parameter, culture);
            }
            catch (Exception exception)
            {
                throw new ArgumentException("The parameter of this converter must be convertible to a double.", exception);
            }

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

        /// <inheritdoc/>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {

View on GitHub (pinned to 96fad776d2)