stride3d/stride · error · ArgumentException
Inconsistent number of parameters: expected 1, 2 or 4…
Error message
Inconsistent number of parameters: expected 1, 2 or 4 values, got {values.Length}. What it means
ThicknessMultiConverter.Convert builds a Thickness from an array of binding values and accepts exactly 1 (uniform), 2 (horizontal/vertical), or 4 (left/top/right/bottom) values. It throws this ArgumentException from Convert (ThicknessMultiConverter.cs:36) in the switch's default branch when values.Length is anything else (0, 3, 5+).
Solutions
- Adjust the MultiBinding so it contains exactly 1, 2, or 4 child bindings.
- If you have 3 values, add the missing one or supply a uniform value so the count is 4 (or 2/1 as appropriate).
- If the count is legitimately variable, extend or wrap the converter to handle other arities.
- Validate bindings.Length before assigning the converter in code.
Example fix
// before <multi:Binding .../> <!-- 3 bindings: left, top, right --> // after (add the missing bottom binding) <multi:Binding .../> <!-- 4 bindings: left, top, right, bottom -->
Defensive patterns
Strategy: validation
Validate before calling
bool ok = values is not null && (values.Length == 1 || values.Length == 2 || values.Length == 4);
Type guard
static bool HasValidArity(object[] v) => v is { Length: 1 or 2 or 4 }; Try / catch
try { return converter.Convert(values, typeof(Thickness), param, culture); }
catch (ArgumentException) { return new Thickness(0); } Prevention
- Count MultiBinding children whenever you add or remove a binding in XAML.
- Remember the supported arities: 1 (uniform), 2 (horizontal/vertical), 4 (l/t/r/b).
- Build complex MultiBindings in code where counts are checked at compile/author time.
When it happens
Trigger: A MultiBinding with 0, 3, or more than 4 child bindings feeding this converter — e.g. three separate left/top/right bindings, or an empty bindings list.
Common situations: Adding/removing a binding in XAML without updating the count expected by the converter; forgetting to bind the fourth side; building the MultiBinding programmatically and miscounting.
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
- The number of provided bindings to this converter must be 2.
- ConvertBack is not supported with this ValueConverter.
- ConvertBack is not supported with this ValueConverter.
- is not a numeric type
- No multi value converter has been set.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a8a749309e9c158e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/ThicknessMultiConverter.cs:36
{
case 1:
var uniform = ConverterHelper.ConvertToDouble(values[0], culture);
return new Thickness(uniform);
case 2:
var horizontal = ConverterHelper.ConvertToDouble(values[0], culture);
var vertical = ConverterHelper.ConvertToDouble(values[1], culture);
return new Thickness(horizontal, vertical, horizontal, vertical);
case 4:
var left = ConverterHelper.ConvertToDouble(values[0], culture);
var top = ConverterHelper.ConvertToDouble(values[1], culture);
var right = ConverterHelper.ConvertToDouble(values[2], culture);
var bottom = ConverterHelper.ConvertToDouble(values[3], culture);
return new Thickness(left, top, right, bottom);
default:
throw new ArgumentException($"Inconsistent number of parameters: expected 1, 2 or 4 values, got {values.Length}.", nameof(values));
}
}
}
}
View on GitHub (pinned to 96fad776d2)