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 Thickness structure.

What it means

SumThickness.Convert adds two WPF Thickness structures component-wise (Left/Top/Right/Bottom). It throws this ArgumentException from Convert (SumThickness.cs:24) when `value` is not a Thickness, because the addition and cast that follow require it. Note the message says "ConvertBack" — a copy-paste bug in the message text; the check lives in Convert.

Solutions

  1. Make the bound source property a System.Windows.Thickness.
  2. Convert the source value to Thickness (e.g. new Thickness(l,t,r,b)) before it reaches the converter.
  3. Type-guard at the call site: `if (value is Thickness)` before calling Convert.
  4. Wrap the converter to return Binding.DoNothing or a default Thickness for invalid input.

Example fix

// before
var t = converter.Convert(new Rect(0,0,5,5), typeof(Thickness), new Thickness(1), culture); // throws
// after
var t = converter.Convert(new Thickness(0,0,5,5), typeof(Thickness), new Thickness(1), culture);
Defensive patterns

Strategy: type-guard

Validate before calling

bool ok = value is System.Windows.Thickness && parameter is System.Windows.Thickness;

Type guard

static bool IsConvertibleValue(object v) => v is System.Windows.Thickness;

Try / catch

try { return converter.Convert(value, typeof(Thickness), param, culture); }
catch (ArgumentException) { return new Thickness(0); }

Prevention

When it happens

Trigger: Binding a non-Thickness value (string, double, Rect, null) into a one-way binding using SumThickness, or calling Convert directly with a non-Thickness object.

Common situations: Binding to a Padding/Margin-like property whose source type is a custom thickness or string; null arriving via a failed binding; tests exercising Convert with placeholder objects; confusion with converters that parse "l,t,r,b" strings.

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


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/52ace47977677c3c. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/SumThickness.cs:24

using System.Windows.Data;
using Stride.Core.Annotations;

namespace Stride.Core.Presentation.ValueConverters
{
    /// <summary>
    /// This converter will sum a given <see cref="Thickness"/> with a <see cref="Thickness"/> passed as parameter. You can use
    /// the <see cref="MarkupExtensions.ThicknessExtension"/> markup extension to easily pass one, with the following syntax: {sd:Thickness (arguments)}. 
    /// </summary>
    [ValueConversion(typeof(Thickness), typeof(Thickness))]
    public class SumThickness : ValueConverterBase<SumThickness>
    {
        /// <inheritdoc/>
        [NotNull]
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is Thickness))
            {
                throw new ArgumentException("The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
            }
            if (!(parameter is Thickness))
            {
                throw new ArgumentException("The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.");
            }

            var sizeValue = (Thickness)value;
            var sizeParameter = (Thickness)parameter;
            var result = new Thickness(sizeValue.Left + sizeParameter.Left, sizeValue.Top + sizeParameter.Top, sizeValue.Right + sizeParameter.Right, sizeValue.Bottom + sizeParameter.Bottom);
            return result;
        }

        /// <inheritdoc/>
        [NotNull]
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is Thickness))
            {

View on GitHub (pinned to 96fad776d2)