{"record":{"id":"18d2d124f46d3dbd","repo":"dotnet/wpf","slug":"sr-format-sr-cannotconverttype-typeof-cornerradius","errorCode":null,"errorMessage":"SR.Format(SR.CannotConvertType, typeof(CornerRadius), destinationType.FullName)","messagePattern":"SR\\.Format\\(SR\\.CannotConvertType, typeof\\(CornerRadius\\), destinationType\\.FullName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs","lineNumber":134,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            ArgumentNullException.ThrowIfNull(destinationType);\n\n            if (!(value is CornerRadius))\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(CornerRadius)), nameof(value));\n            }\n\n            CornerRadius cr = (CornerRadius)value;\n            if (destinationType == typeof(string)) { return ToString(cr, cultureInfo); }\n            if (destinationType == typeof(InstanceDescriptor))\n            {\n                ConstructorInfo ci = typeof(CornerRadius).GetConstructor(new Type[] { typeof(double), typeof(double), typeof(double), typeof(double) });\n                return new InstanceDescriptor(ci, new object[] { cr.TopLeft, cr.TopRight, cr.BottomRight, cr.BottomLeft });\n            }\n\n            throw new ArgumentException(SR.Format(SR.CannotConvertType, typeof(CornerRadius), destinationType.FullName));\n        }\n\n        #endregion Public Methods\n\n        //-------------------------------------------------------------------\n        //\n        //  Internal Methods\n        //\n        //-------------------------------------------------------------------\n\n        #region Internal Methods\n\n        internal static string ToString(CornerRadius cr, CultureInfo cultureInfo)\n        {\n            char listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);\n\n            return string.Create(cultureInfo, stackalloc char[64], $\"{cr.TopLeft}{listSeparator}{cr.TopRight}{listSeparator}{cr.BottomRight}{listSeparator}{cr.BottomLeft}\");\n        }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs#L116-L152","documentation":"CornerRadiusConverter.ConvertTo only supports converting to string and InstanceDescriptor; any other destinationType falls through to this ArgumentException built from SR.CannotConvertType, reporting typeof(CornerRadius) and the unsupported destination type's full name. This is the converter's 'unsupported target type' terminal case.","triggerScenarios":"ConvertTo(ctx, culture, cornerRadius, typeof(int)) or any destinationType other than typeof(string) and typeof(InstanceDescriptor).","commonSituations":"Custom serializers exporting properties to CSV/JSON by asking converters for arbitrary types; tooling that requests byte[] or Xml representation of WPF values.","solutions":["Only request typeof(string) or typeof(InstanceDescriptor) from this converter.","Convert to string first, then parse/transform the string into your desired target type yourself.","Write a custom TypeConverter or mapper for unsupported destination types."],"exampleFix":"// before\nvar n = (int)converter.ConvertTo(ctx, culture, cr, typeof(int));\n// after\nstring s = (string)converter.ConvertTo(ctx, culture, cr, typeof(string));\n// transform s into the target representation yourself","handlingStrategy":"validation","validationCode":"static readonly Type[] Supported = { typeof(string), typeof(InstanceDescriptor) };\nif (!Supported.Contains(destinationType))\n    throw new NotSupportedException($\"CornerRadiusConverter cannot convert to {destinationType?.FullName}\");","typeGuard":"static bool IsSupportedDest(Type t) => t == typeof(string) || t == typeof(InstanceDescriptor);","tryCatchPattern":"try { return converter.ConvertTo(ctx, culture, cr, destType); } catch (ArgumentException) { return cr.ToString(CultureInfo.InvariantCulture); }","preventionTips":["Restrict generic conversion calls to string or InstanceDescriptor destinations.","Convert to string first, then transform for other formats.","Document converter-supported destinations wherever converters are invoked generically."],"tags":["wpf","typeconverter","unsupported-conversion","argument"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}