stride3d/stride · error · ArgumentException

The number of provided bindings to this converter must be 2.

Error message

The number of provided bindings to this converter must be 2.

What it means

TrimString is a multi-value converter that requires exactly two bindings: values[0] is the text to trim and values[1] is the Control or TextBlock that displays it. It throws this ArgumentException from Convert (TrimString.cs:27) when the values array length is not 2.

Solutions

  1. Ensure the MultiBinding has exactly two bindings: the string and the Control/TextBlock itself.
  2. Bind the second value to the displaying element, e.g. `{Binding RelativeSource={RelativeSource Self}}`.
  3. Move optional settings (TextTrimming, WordSeparators, MaxWidth) onto the converter's properties, not as additional bindings.
  4. Validate values.Length == 2 before calling Convert in code/tests.

Example fix

// before (1 binding only)
<MultiBinding Converter="{StaticResource TrimString}">
  <Binding Path="Text"/>
</MultiBinding>
// after
<MultiBinding Converter="{StaticResource TrimString}">
  <Binding Path="Text"/>
  <Binding RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
Defensive patterns

Strategy: validation

Validate before calling

bool ok = values is { Length: 2 };

Type guard

static bool HasValidArity(object[] v) => v is { Length: 2 };

Try / catch

try { return converter.Convert(values, targetType, param, culture); }
catch (ArgumentException) { return string.Empty; }

Prevention

When it happens

Trigger: A MultiBinding with fewer or more than 2 child bindings attached to TrimString — e.g. only the text binding without the control binding, or extra bindings for trim options.

Common situations: Forgetting the second binding (the target control) when wiring text trimming; adding extra bindings for options that TrimString expects as properties instead; programmatic MultiBinding construction with the wrong count.

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

Appendix: source

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

namespace Stride.Core.Presentation.ValueConverters
{
    public class TrimString : OneWayMultiValueConverter<TrimString>
    {
        public double MaxWidth { get; set; }

        public TextTrimming TextTrimming { get; set; }

        public TrimmingSource TrimmingSource { get; set; }

        public string WordSeparators { get; set; }

        /// <inheritdoc />
        public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null) throw new ArgumentNullException(nameof(values));
            if (values.Length != 2)
                throw new ArgumentException("The number of provided bindings to this converter must be 2.");

            var text = values[0]?.ToString() ?? string.Empty;
            if (values[1] is Control control)
                return Trimming.ProcessTrimming(control, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth);
            if (values[1] is TextBlock textBlock)
                return Trimming.ProcessTrimming(textBlock, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth);
            return text;
        }

        /// <inheritdoc />
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            // Note: necessary because properties can be different for each instance of this converter.
            return this;
        }
    }
}

View on GitHub (pinned to 96fad776d2)