stride3d/stride · error · InvalidOperationException

This multi converter must be invoked with at least two eleme

Error message

This multi converter must be invoked with at least two elements

What it means

MultiplyMultiConverter is a WPF IMultiValueConverter that multiplies all of its input bindings together to produce a single double result. It requires at least two bound values because multiplying fewer than two elements is meaningless for this converter. The library throws this InvalidOperationException when the converter is invoked with a values array of length 0 or 1, which typically means the XAML MultiBinding is missing or has only one Binding child.

Solutions

  1. Ensure the MultiBinding in XAML declares at least two <Binding> children inside <MultiBinding.Converter>
  2. Check that all source bindings resolve to non-null values at conversion time
  3. If calling Convert programmatically, pass an array with two or more elements
  4. Use an IMultiValueConverter wrapper or fallback value (FallbackValue/TargetNullValue) for optional bindings

Example fix

// before
<MultiBinding Converter="{sd:MultiplyMultiConverter}">
  <Binding Path="Width"/>
</MultiBinding>
// after
<MultiBinding Converter="{sd:MultiplyMultiConverter}">
  <Binding Path="Width"/>
  <Binding Path="Scale"/>
</MultiBinding>
Defensive patterns

Strategy: validation

Validate before calling

if (values == null || values.Length < 2)
    throw new InvalidOperationException("MultiplyMultiConverter requires at least two bound values");

Type guard

bool HasEnoughValues(object[] values) => values != null && values.Length >= 2;

Try / catch

try
{
    var result = converter.Convert(values, typeof(double), null, CultureInfo.CurrentCulture);
}
catch (InvalidOperationException ex)
{
    // log & fall back to a default product value
}

Prevention

When it happens

Trigger: Calling Convert(object[] values, ...) with an array of length < 2, e.g. a MultiBinding with no <Binding> children, a MultiBinding with exactly one binding, or programmatic invocation passing new object[] { 1.0 } or an empty array.

Common situations: XAML refactoring accidentally removed one of the MultiBinding's Binding elements; a binding failed to resolve so WPF passed a shorter values array; a developer unit-testing or calling the converter directly forgot to supply at least two values.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/MultiplyMultiConverter.cs:16

// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Globalization;
using System.Linq;
using Stride.Core.Annotations;

namespace Stride.Core.Presentation.ValueConverters
{
    public class MultiplyMultiConverter : OneWayMultiValueConverter<MultiplyMultiConverter>
    {
        [NotNull]
        public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length < 2)
                throw new InvalidOperationException("This multi converter must be invoked with at least two elements");

            var result = 1.0;
            try
            {
                result = values.Select(x => ConverterHelper.ConvertToDouble(x, culture)).Aggregate(result, (current, next) => current * next);
            }
            catch (Exception exception)
            {
                throw new ArgumentException("The values of this converter must be convertible to a double.", exception);
            }

            return result;
        }
    }
}

View on GitHub (pinned to 96fad776d2)