{"record":{"id":"169c6550271814d9","repo":"stride3d/stride","slug":"the-value-of-this-converter-must-be-convertible-to-a-double-169c65","errorCode":null,"errorMessage":"The value of this converter must be convertible to a double.","messagePattern":"The value of this converter must be convertible to a double\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToSize.cs","lineNumber":31,"sourceCode":"    /// A <see cref=\"Size\"/> must be passed as a parameter of this converter. You can use the <see cref=\"MarkupExtensions.SizeExtension\"/>\n    /// markup extension to easily pass one, with the following syntax: {sd:Size (arguments)}. The resulting size will\n    /// be the parameter size multiplied bu the scalar double value.\n    /// </summary>\n    [ValueConversion(typeof(double), typeof(Size))]\n    public class NumericToSize : ValueConverterBase<NumericToSize>\n    {\n        /// <inheritdoc/>\n        [NotNull]\n        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n        {\n            double scalar;\n            try\n            {\n                scalar = ConverterHelper.ConvertToDouble(value, culture);\n            }\n            catch (Exception exception)\n            {\n                throw new ArgumentException(\"The value of this converter must be convertible to a double.\", exception);\n            }\n\n            if (!(parameter is Size))\n            {\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.\");","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToSize.cs#L13-L49","documentation":"NumericToSize multiplies a WPF Size structure (given as the converter parameter) by a numeric scalar (the bound value). The scalar is obtained via ConverterHelper.ConvertToDouble; when that conversion fails the library wraps the failure in this ArgumentException with the original exception as InnerException. It exists to fail fast when the bound value is not numeric rather than produce a degenerate Size.","triggerScenarios":"Convert(value, targetType, parameter, culture) is called with a value that ConverterHelper.ConvertToDouble cannot interpret: a non-numeric string like \"auto\", a Brush/Control instance, null, or a badly formatted localized number.","commonSituations":"Binding a string dimension (e.g. from a TextBox) instead of a numeric property; binding an object/enum to a Size-scaled element; culture-specific decimal separators breaking string-to-double conversion.","solutions":["Bind a numeric property (int/double) as the converter value","Inspect InnerException to find the offending value","Parse strings to numbers in the view model before binding","Use CultureInfo-invariant parsing if strings come from user input"],"exampleFix":"// before\n<Binding Path=\"WidthText\"/> <!-- \"12,5\" string -->\n// after\n<Binding Path=\"Width\"/> <!-- double 12.5 -->","handlingStrategy":"validation","validationCode":"bool CanScaleToSize(object value) =>\n    value is double || value is int || value is float || value is long || value is decimal ||\n    (value is string s && double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out _));","typeGuard":"bool IsDoubleConvertible(object v) => v is double || v is int || v is float || v is long || v is decimal;","tryCatchPattern":"try\n{\n    return converter.Convert(value, typeof(Size), sizeParameter, culture);\n}\ncatch (ArgumentException ex)\n{\n    Log(ex.InnerException);\n    return (Size)sizeParameter; // unscaled fallback\n}","preventionTips":["Bind numeric properties, not strings, as the scalar","Use invariant parsing for user-entered numbers before they reach the converter","Inspect InnerException when diagnosing culture/format issues","Keep conversion of raw inputs in the view model layer"],"tags":["wpf","valueconverter","size","double-conversion"],"backgroundTag":"invalid-argument-value","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"}