{"record":{"id":"5b9dc02b17b146e5","repo":"stride3d/stride","slug":"this-multi-converter-must-be-invoked-with-at-least-two-5b9dc0","errorCode":null,"errorMessage":"This multi converter must be invoked with at least two elements","messagePattern":"This multi converter must be invoked with at least two elements","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/XOrMultiConverter.cs","lineNumber":17,"sourceCode":"// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\nusing System;\nusing System.Globalization;\nusing System.Linq;\nusing Stride.Core.Annotations;\nusing Stride.Core.Presentation.Internal;\n\nnamespace Stride.Core.Presentation.ValueConverters\n{\n    public class XOrMultiConverter : OneWayMultiValueConverter<XOrMultiConverter>\n    {\n        [NotNull]\n        public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture)\n        {\n            if (values.Length < 2)\n                throw new InvalidOperationException(\"This multi converter must be invoked with at least two elements\");\n\n            var result = values.Skip(1).Aggregate((bool)values[0], (current, value) => current ^ (bool)value);\n            return result.Box();\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/XOrMultiConverter.cs#L1-L24","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the MultiBinding declares at least two child Bindings","If you need single-value XOR semantics, use a different converter or return values[0] when only one value is supplied","When calling Convert directly, pass at least two boolean elements in the values array"],"exampleFix":"// before\n<MultiBinding Converter=\"{StaticResource XOr}\"><Binding Path=\"A\"/></MultiBinding>\n// after\n<MultiBinding Converter=\"{StaticResource XOr}\"><Binding Path=\"A\"/><Binding Path=\"B\"/></MultiBinding>","handlingStrategy":"validation","validationCode":"if (values == null || values.Length < 2) return values?.FirstOrDefault() ?? DependencyProperty.UnsetValue;","typeGuard":"bool CanXor(object[] values) => values != null && values.Length >= 2;","tryCatchPattern":"try { return converter.Convert(values, targetType, null, culture); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"at least two elements\")) { return DependencyProperty.UnsetValue; }","preventionTips":["Keep MultiBinding child Bindings in sync with converter expectations","Verify binding count after refactoring XAML","Write unit tests for converters with minimal value arrays"],"tags":["wpf","multibinding","value-converter"],"backgroundTag":"missing-required-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}