dotnet/wpf · error · ArgumentException
SR.Format(SR.CannotConvertType, typeof(CornerRadius)…
Error message
SR.Format(SR.CannotConvertType, typeof(CornerRadius), destinationType.FullName)
What it means
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.
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.
Example fix
// before var n = (int)converter.ConvertTo(ctx, culture, cr, typeof(int)); // after string s = (string)converter.ConvertTo(ctx, culture, cr, typeof(string)); // transform s into the target representation yourself
Defensive patterns
Strategy: validation
Validate before calling
static readonly Type[] Supported = { typeof(string), typeof(InstanceDescriptor) };
if (!Supported.Contains(destinationType))
throw new NotSupportedException($"CornerRadiusConverter cannot convert to {destinationType?.FullName}"); Type guard
static bool IsSupportedDest(Type t) => t == typeof(string) || t == typeof(InstanceDescriptor);
Try / catch
try { return converter.ConvertTo(ctx, culture, cr, destType); } catch (ArgumentException) { return cr.ToString(CultureInfo.InvariantCulture); } Prevention
- 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.
When it happens
Trigger: ConvertTo(ctx, culture, cornerRadius, typeof(int)) or any destinationType other than typeof(string) and typeof(InstanceDescriptor).
Common situations: Custom serializers exporting properties to CSV/JSON by asking converters for arbitrary types; tooling that requests byte[] or Xml representation of WPF values.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot convert to type.
- SR.Format(SR.CannotConvertType, typeof(PropertyPath)…
- SR.Format(SR.General_BadType, "ConvertFrom")
- SR.Format(SR.General_Expected_Type, nameof(PixelFormat))
- SR.Format(SR.MustBeOfType, "value"…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/18d2d124f46d3dbd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs:134
{
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(destinationType);
if (!(value is CornerRadius))
{
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(CornerRadius)), nameof(value));
}
CornerRadius cr = (CornerRadius)value;
if (destinationType == typeof(string)) { return ToString(cr, cultureInfo); }
if (destinationType == typeof(InstanceDescriptor))
{
ConstructorInfo ci = typeof(CornerRadius).GetConstructor(new Type[] { typeof(double), typeof(double), typeof(double), typeof(double) });
return new InstanceDescriptor(ci, new object[] { cr.TopLeft, cr.TopRight, cr.BottomRight, cr.BottomLeft });
}
throw new ArgumentException(SR.Format(SR.CannotConvertType, typeof(CornerRadius), destinationType.FullName));
}
#endregion Public Methods
//-------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
internal static string ToString(CornerRadius cr, CultureInfo cultureInfo)
{
char listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);
return string.Create(cultureInfo, stackalloc char[64], $"{cr.TopLeft}{listSeparator}{cr.TopRight}{listSeparator}{cr.BottomRight}{listSeparator}{cr.BottomLeft}");
}View on GitHub (pinned to 81131a70a4)