{"record":{"id":"e82af44716fe7b02","repo":"HandyOrg/HandyControl","slug":"cannotconverttype","errorCode":null,"errorMessage":"CannotConvertType","messagePattern":"CannotConvertType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/HandyControl_Avalonia/Tools/Converter/ColLayoutConverter.cs","lineNumber":44,"sourceCode":"    public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)\n    {\n        if (value == null) throw GetConvertFromException(null!);\n\n        return value switch\n        {\n            string s => ColLayout.Parse(s),\n            double d => new ColLayout((int) d),\n            _ => new ColLayout(System.Convert.ToInt32(value, culture))\n        };\n    }\n\n    public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)\n    {\n        if (value is ColLayout layout && destinationType == typeof(string))\n        {\n            return layout.ToString();\n        }\n        throw new ArgumentException(\"CannotConvertType\");\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":47,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Avalonia/HandyControl_Avalonia/Tools/Converter/ColLayoutConverter.cs#L26-L47","documentation":"ColLayoutConverter.ConvertTo only supports converting a ColLayout instance to a string (via its ToString). Any other value type or destination type makes it throw an ArgumentException('CannotConvertType'), mirroring the .NET TypeConverter contract where an unsupported conversion is signalled with ArgumentException rather than a specific exception type.","triggerScenarios":"Calling TypeDescriptor.GetConverter(colLayout).ConvertTo(value, destinationType) with destinationType other than typeof(string), or passing a value that is not a ColLayout (e.g. null, a raw string, a Col object) into ConvertTo.","commonSituations":"XAML or designer serialization trying to convert a ColLayout to InstanceDescriptor or another type; data-binding engines attempting non-string conversions; unit tests exercising the converter with wrong destination types.","solutions":["Only call ConvertTo with a ColLayout value and destinationType == typeof(string); use ConvertFrom/Parse for the string->layout direction","For other destination types, register a custom TypeConverter or handle the conversion yourself before invoking the converter","Wrap the ConvertTo call in try/catch (ArgumentException) if conversion support is probed dynamically"],"exampleFix":"// before\nvar result = converter.ConvertTo(null, CultureInfo.InvariantCulture, \"24,12,8\", typeof(string)); // throws\n// after\nvar layout = ColLayout.Parse(\"24,12,8\");\nvar result = converter.ConvertTo(null, CultureInfo.InvariantCulture, layout, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (value is ColLayout && destinationType == typeof(string)) { /* safe to call ConvertTo */ }","typeGuard":"static bool CanConvert(object? v, Type t) => v is ColLayout && t == typeof(string);","tryCatchPattern":"try { return converter.ConvertTo(null, culture, value, typeof(string)); }\ncatch (ArgumentException) { return value?.ToString(); }","preventionTips":["Only use ColLayoutConverter for string conversions","Use TypeConverter.CanConvertTo before calling ConvertTo","Keep ColLayout objects intact until serialization time"],"tags":["typeconverter","xaml","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}