{"record":{"id":"a4a271d7de6e44a2","repo":"stride3d/stride","slug":"the-value-of-the-convertback-method-of-this-converter-must-a4a271","errorCode":null,"errorMessage":"The value of the ConvertBack method of this converter must be a an instance of the Size structure.","messagePattern":"The value of the ConvertBack method of this converter must be a an instance of the Size structure\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/SumSize.cs","lineNumber":24,"sourceCode":"using System.Windows.Data;\nusing Stride.Core.Annotations;\n\nnamespace Stride.Core.Presentation.ValueConverters\n{\n    /// <summary>\n    /// 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\"/>\n    /// markup extension to easily pass one, with the following syntax: {sd:Size (arguments)}. \n    /// </summary>\n    [ValueConversion(typeof(Size), typeof(Size))]\n    public class SumSize : ValueConverterBase<SumSize>\n    {\n        /// <inheritdoc/>\n        [NotNull]\n        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n        {\n            if (!(value is Size))\n            {\n                throw new ArgumentException(\"The value of the ConvertBack method of this converter must be a an instance of the Size structure.\");\n            }\n            if (!(parameter is Size))\n            {\n                throw new ArgumentException(\"The parameter of the ConvertBack method of this converter must be a an instance of the Size structure.\");\n            }\n\n            var sizeValue = (Size)value;\n            var sizeParameter = (Size)parameter;\n            var result = new Size(sizeValue.Width + sizeParameter.Width, sizeValue.Height + sizeParameter.Height);\n            return result;\n        }\n\n        /// <inheritdoc/>\n        [NotNull]\n        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\n        {\n            if (!(value is Size))\n            {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/SumSize.cs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconverter.Convert(element.Width, typeof(Size), new Size(1,1), culture); // double -> throws\n// after\nconverter.Convert(new Size(element.Width, element.Height), typeof(Size), new Size(1,1), culture);","handlingStrategy":"type-guard","validationCode":"bool ok = value is System.Windows.Size && parameter is System.Windows.Size;","typeGuard":"static bool IsSizePair(object value, object parameter) => value is System.Windows.Size && parameter is System.Windows.Size;","tryCatchPattern":"try { return sumSize.Convert(value, targetType, parameter, culture); }\ncatch (ArgumentException) { return Binding.DoNothing; }","preventionTips":["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"],"tags":["wpf","valueconverter","type-mismatch","size"],"backgroundTag":"type-mismatch","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"}