{"record":{"id":"e6bdf00c53e144b3","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-e6bdf0","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(CornerRadius))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(CornerRadius\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs","lineNumber":123,"sourceCode":"        /// An ArgumentNullException is thrown if the example object is null.\n        /// </exception>\n        /// <exception cref=\"ArgumentException\">\n        /// An ArgumentException is thrown if the object is not null and is not a CornerRadius,\n        /// or if the destinationType isn't one of the valid destination types.\n        /// </exception>\n        /// <param name=\"typeDescriptorContext\"> The ITypeDescriptorContext for this call. </param>\n        /// <param name=\"cultureInfo\"> The CultureInfo which is respected when converting. </param>\n        /// <param name=\"value\"> The CornerRadius to convert. </param>\n        /// <param name=\"destinationType\">The type to which to convert the CornerRadius instance. </param>\n        public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)\n        {\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","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs#L105-L141","documentation":"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).","triggerScenarios":"Calling TypeDescriptor.GetConverter(typeof(CornerRadius)).ConvertTo(ctx, culture, someNonCornerRadiusValue, typeof(string)); passing null-adjacent wrong types like a Thickness or double into ConvertTo.","commonSituations":"Generic serialization code that assumes converters accept any value; reflection-based XAML/property serializers feeding mismatched property values to the converter.","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."],"exampleFix":"// before\nconverter.ConvertTo(ctx, culture, thickness, typeof(string));\n// after\nif (value is CornerRadius cr)\n    converter.ConvertTo(ctx, culture, cr, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (value is not CornerRadius)\n    throw new ArgumentException($\"Expected CornerRadius, got {value?.GetType().Name}\", nameof(value));","typeGuard":"static bool CanConvertTo(object v) => v is CornerRadius;","tryCatchPattern":"try { return converter.ConvertTo(ctx, culture, value, destType); } catch (ArgumentException ex) when (ex.ParamName == \"value\") { return value?.ToString(); }","preventionTips":["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."],"tags":["wpf","typeconverter","argument","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}