stride3d/stride · error · InvalidOperationException

This multi converter must be invoked with at least two…

Error message

This multi converter must be invoked with at least two elements

What it means

XOrMultiConverter computes the XOR of all input values, which requires at least two booleans to be meaningful. When the WPF MultiBinding supplies fewer than two values (typically because fewer bindings were declared than expected), Convert throws InvalidOperationException instead of returning a wrong result.

Solutions

  1. Ensure the MultiBinding declares at least two child Bindings
  2. If you need single-value XOR semantics, use a different converter or return values[0] when only one value is supplied
  3. When calling Convert directly, pass at least two boolean elements in the values array

Example fix

// before
<MultiBinding Converter="{StaticResource XOr}"><Binding Path="A"/></MultiBinding>
// after
<MultiBinding Converter="{StaticResource XOr}"><Binding Path="A"/><Binding Path="B"/></MultiBinding>
Defensive patterns

Strategy: validation

Validate before calling

if (values == null || values.Length < 2) return values?.FirstOrDefault() ?? DependencyProperty.UnsetValue;

Type guard

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

Try / catch

try { return converter.Convert(values, targetType, null, culture); } catch (InvalidOperationException ex) when (ex.Message.Contains("at least two elements")) { return DependencyProperty.UnsetValue; }

Prevention

When it happens

Trigger: Calling Convert with an object[] of length 0 or 1, e.g. a MultiBinding with a single child Binding, or invoking the converter directly in unit tests with a one-element array.

Common situations: Removing or commenting out one of the bindings inside a MultiBinding without removing the converter; a binding failing to produce a value so the values array collapses; programmatic conversion with a hand-built array.

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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/XOrMultiConverter.cs:17

// 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;
using Stride.Core.Presentation.Internal;

namespace Stride.Core.Presentation.ValueConverters
{
    public class XOrMultiConverter : OneWayMultiValueConverter<XOrMultiConverter>
    {
        [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 = values.Skip(1).Aggregate((bool)values[0], (current, value) => current ^ (bool)value);
            return result.Box();
        }
    }
}

View on GitHub (pinned to 96fad776d2)