stride3d/stride · error · ArgumentException
The value of the ConvertBack method of this converter must…
Error message
The value of the ConvertBack method of this converter must be a an instance of the Size structure.
What it means
SumSize.Convert adds two Size structures and validates that both the converted value and the parameter are instances of System.Windows.Size. The first check throws ArgumentException when the value is not a Size. Note the message text mistakenly says 'ConvertBack method' even though it is raised in Convert — a copy/paste artifact in the library.
Solutions
- Pass System.Windows.Size instances for both value and parameter (e.g. bind to ActualSize-style properties of type Size).
- Convert doubles into a Size before invoking the converter.
- Use a different arithmetic converter for scalar types.
Example fix
// before converter.Convert(element.Width, typeof(Size), new Size(1,1), culture); // double -> throws // after converter.Convert(new Size(element.Width, element.Height), typeof(Size), new Size(1,1), culture);
Defensive patterns
Strategy: type-guard
Validate before calling
bool ok = value is System.Windows.Size && parameter is System.Windows.Size;
Type guard
static bool IsSizePair(object value, object parameter) => value is System.Windows.Size && parameter is System.Windows.Size;
Try / catch
try { return sumSize.Convert(value, targetType, parameter, culture); }
catch (ArgumentException) { return Binding.DoNothing; } Prevention
- Bind only properties of type Size through SumSize
- Construct Size parameters explicitly in code or resources
- Do not reuse SumSize for scalar Width/Height values
- Beware the message text mentions ConvertBack although thrown from Convert
When it happens
Trigger: Calling SumSize.Convert with a value that is not a Size — e.g. a double, string, Vector, or null — while the parameter may or may not be valid.
Common situations: Binding an element's non-size property through SumSize; passing scalars expecting implicit conversion; reusing the converter for Width/Height (doubles) instead of full Size values.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- The parameter of the ConvertBack method of this converter…
- is not a numeric type
- The value of this converter must be convertible to a double.
- The parameter of this converter must be an instance of the…
- The value of the ConvertBack method of this converter must…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a4a271d7de6e44a2.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/SumSize.cs:24
using System.Windows.Data;
using Stride.Core.Annotations;
namespace Stride.Core.Presentation.ValueConverters
{
/// <summary>
/// This converter will sum a given <see cref="Size"/> with a <see cref="Size"/> passed as parameter. You can use the <see cref="MarkupExtensions.SizeExtension"/>
/// markup extension to easily pass one, with the following syntax: {sd:Size (arguments)}.
/// </summary>
[ValueConversion(typeof(Size), typeof(Size))]
public class SumSize : ValueConverterBase<SumSize>
{
/// <inheritdoc/>
[NotNull]
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is Size))
{
throw new ArgumentException("The value of the ConvertBack method of this converter must be a an instance of the Size structure.");
}
if (!(parameter is Size))
{
throw new ArgumentException("The parameter of the ConvertBack method of this converter must be a an instance of the Size structure.");
}
var sizeValue = (Size)value;
var sizeParameter = (Size)parameter;
var result = new Size(sizeValue.Width + sizeParameter.Width, sizeValue.Height + sizeParameter.Height);
return result;
}
/// <inheritdoc/>
[NotNull]
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is Size))
{View on GitHub (pinned to 96fad776d2)