{"record":{"id":"8ba222564240b888","repo":"stride3d/stride","slug":"the-parameter-of-the-convertback-method-of-this-converter","errorCode":null,"errorMessage":"The parameter of the ConvertBack method of this converter must be a an instance of the Size structure.","messagePattern":"The parameter 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/NumericToSize.cs","lineNumber":53,"sourceCode":"            {\n                throw new ArgumentException(\"The parameter of this converter must be an instance of the Size structure. Use {sd:Size (arguments)} to construct one.\");\n            }\n\n            var size = (Size)parameter;\n            var result = new Size(size.Width * scalar, size.Height * scalar);\n            return result;\n        }\n\n        /// <inheritdoc/>\n        public override object ConvertBack(object value, [NotNull] 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            var sizeValue = (Size)value;\n            var sizeParameter = (Size)parameter;\n\n            var scalar = 0.0;\n            if (Math.Abs(sizeParameter.Width) > double.Epsilon)\n            {\n                scalar = sizeValue.Width / sizeParameter.Width;\n            }\n            else if (Math.Abs(sizeParameter.Height) > double.Epsilon)\n            {\n                scalar = sizeValue.Height / sizeParameter.Height;\n            }\n\n            return System.Convert.ChangeType(scalar, targetType);\n        }\n    }\n}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToSize.cs#L35-L71","documentation":"NumericToSize.ConvertBack requires both the value and the ConverterParameter to be System.Windows.Size instances; the parameter supplies the reference size used to recover the scalar (value.Width / parameter.Width). If parameter is not a Size this ArgumentException is thrown. It mirrors the Convert-side parameter check but for the ConvertBack path.","triggerScenarios":"Calling ConvertBack with parameter = null, a string like \"10,20\", or a numeric; using the converter in TwoWay mode without the {sd:Size} markup-extension parameter.","commonSituations":"Two-way bindings where the ConverterParameter was authored as a plain string; forgetting to update the parameter when switching the binding to TwoWay; programmatic tests calling ConvertBack with primitive parameters.","solutions":["Provide the parameter as a Size via ConverterParameter=\"{sd:Size w, h}\"","Ensure both value and parameter are Size instances before ConvertBack runs","Switch to OneWay mode if ConvertBack is not actually needed","Pass a real Size struct when calling ConvertBack from code/tests"],"exampleFix":"// before\nConverter=\"{sd:NumericToSize}\" ConverterParameter=\"10,20\" Mode=\"TwoWay\"\n// after\nConverter=\"{sd:NumericToSize}\" ConverterParameter=\"{sd:Size 10,20}\" Mode=\"TwoWay\"","handlingStrategy":"type-guard","validationCode":"bool CanConvertBack(object value, object parameter) => value is System.Windows.Size && parameter is System.Windows.Size;","typeGuard":"bool IsSizePair(object v, object p) => v is System.Windows.Size && p is System.Windows.Size;","tryCatchPattern":"try\n{\n    return converter.ConvertBack(value, typeof(double), parameter, culture);\n}\ncatch (ArgumentException)\n{\n    return Binding.DoNothing;\n}","preventionTips":["Supply ConverterParameter=\"{sd:Size w, h}\" whenever the binding is TwoWay","Never leave ConverterParameter as a string for TwoWay bindings","Verify value and parameter types in tests that exercise ConvertBack","Switch to OneWay if ConvertBack semantics are not required"],"tags":["wpf","valueconverter","convertback","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"}