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

AndMultiConverter.Convert throws this InvalidOperationException when invoked with fewer than two values, because a logical AND over zero or one inputs has no defined meaning for this converter. It enforces the minimum input count of the MultiBinding.

Solutions

  1. Provide at least two child Bindings in the MultiBinding
  2. Attach via <MultiBinding.Converter> only
  3. Use a regular one-way converter instead when a single condition is all you need

Example fix

// before
<MultiBinding Converter="{StaticResource AndMultiConverter}">
  <Binding Path="IsEnabled"/>
</MultiBinding>
// after
<MultiBinding Converter="{StaticResource AndMultiConverter}">
  <Binding Path="IsEnabled"/>
  <Binding Path="HasPermission"/>
</MultiBinding>
Defensive patterns

Strategy: validation

Validate before calling

if (values == null || values.Length < 2)
    throw new InvalidOperationException("AndMultiConverter needs at least two values");

Type guard

bool HasTwoValues(object[] v) => v != null && v.Length >= 2;

Try / catch

try { result = AndMultiConverter.Instance.Convert(values, targetType, param, culture); }
catch (InvalidOperationException ex) { Log.Warn("Insufficient binding values", ex); }

Prevention

When it happens

Trigger: MultiBinding with only one child binding; child bindings failing so the values array is shorter than two; attaching the converter to a plain single Binding.

Common situations: XAML mistakes where a nested <Binding> is removed or malformed; dynamic bindings that fail at runtime; reuse of the converter in templates with one condition only.

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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/AndMultiConverter.cs:18

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

namespace Stride.Core.Presentation.ValueConverters
{
    public class AndMultiConverter : OneWayMultiValueConverter<AndMultiConverter>
    {
        [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 fallbackValue = parameter is bool && (bool)parameter;
            var result = values.All(x => x == DependencyProperty.UnsetValue ? fallbackValue : (bool)x);
            return result.Box();
        }
    }
}

View on GitHub (pinned to 96fad776d2)