dotnet/wpf · error · ArgumentException
SR.Format(SR.UnexpectedParameterType, value.GetType()…
Error message
SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(CornerRadius))
What it means
CornerRadiusConverter.ConvertTo validates that the value being converted is actually a CornerRadius instance; if not, it throws ArgumentException naming the 'value' parameter via SR.UnexpectedParameterType. This is standard TypeConverter contract enforcement (converting a wrong-typed value to string/InstanceDescriptor).
Solutions
- Only pass CornerRadius instances to this converter (check 'value is CornerRadius' first).
- Route the value to the correct converter for its actual runtime type via TypeDescriptor.GetConverter(value.GetType()).
- If the source is a Thickness or similar, explicitly map its fields into a new CornerRadius before conversion.
Example fix
// before
converter.ConvertTo(ctx, culture, thickness, typeof(string));
// after
if (value is CornerRadius cr)
converter.ConvertTo(ctx, culture, cr, typeof(string)); Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not CornerRadius)
throw new ArgumentException($"Expected CornerRadius, got {value?.GetType().Name}", nameof(value)); Type guard
static bool CanConvertTo(object v) => v is CornerRadius;
Try / catch
try { return converter.ConvertTo(ctx, culture, value, destType); } catch (ArgumentException ex) when (ex.ParamName == "value") { return value?.ToString(); } Prevention
- Only feed values of the converter's target type to ConvertTo.
- In generic serializers, look up the converter via TypeDescriptor.GetConverter(value.GetType()).
- Write unit tests covering every value type routed through converter pipelines.
When it happens
Trigger: Calling TypeDescriptor.GetConverter(typeof(CornerRadius)).ConvertTo(ctx, culture, someNonCornerRadiusValue, typeof(string)); passing null-adjacent wrong types like a Thickness or double into ConvertTo.
Common situations: Generic serialization code that assumes converters accept any value; reflection-based XAML/property serializers feeding mismatched property values to the converter.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- 'value' must be of type 'BitmapSource'.
- SR.AnnotationAdorner_NotUIElement
- SR.AudioVideo_InvalidDependencyObject
- SR.Format(SR.BadFixedTextPosition, "position")
- SR.Format(SR.CannotConvertType, key.GetType(), "int")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e6bdf00c53e144b3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs:123
/// An ArgumentNullException is thrown if the example object is null.
/// </exception>
/// <exception cref="ArgumentException">
/// An ArgumentException is thrown if the object is not null and is not a CornerRadius,
/// or if the destinationType isn't one of the valid destination types.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The CornerRadius to convert. </param>
/// <param name="destinationType">The type to which to convert the CornerRadius instance. </param>
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
{
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 MethodsView on GitHub (pinned to 81131a70a4)