{"record":{"id":"568c3c91d8db195d","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-568c3c","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PropertyPath))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(PropertyPath\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs","lineNumber":139,"sourceCode":"        /// <param name=\"value\"> The PropertyPath to convert. </param>\n        /// <param name=\"destinationType\">The type to which to convert the PropertyPath instance. </param>\n        public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext,\n                                         CultureInfo cultureInfo,\n                                         object value,\n                                         Type destinationType)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n            ArgumentNullException.ThrowIfNull(destinationType);\n\n            if (destinationType != typeof(String))\n            {\n                throw new ArgumentException(SR.Format(SR.CannotConvertType, typeof(PropertyPath), destinationType.FullName));\n            }\n\n            PropertyPath path = value as PropertyPath;\n            if (path == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PropertyPath)), nameof(value));\n            }\n\n            if (path.PathParameters.Count == 0)\n            {\n                // if the path didn't use paramaters, just write it out as it is\n                return path.Path;\n            }\n            else\n            {\n                // if the path used parameters, convert them to (NamespacePrefix:OwnerType.DependencyPropertyName) syntax\n                string originalPath = path.Path;\n                Collection<object> parameters = path.PathParameters;\n                XamlDesignerSerializationManager manager = typeDescriptorContext == null ?\n                                                                null :\n                                                                typeDescriptorContext.GetService(typeof(XamlDesignerSerializationManager)) as XamlDesignerSerializationManager;\n                ValueSerializer typeSerializer = null;\n                IValueSerializerContext serializerContext = null;\n                if (manager == null)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs#L121-L157","documentation":"PropertyPathConverter.ConvertTo can only serialize a value that is actually a PropertyPath. When ConvertTo is invoked with a null or non-PropertyPath value, an ArgumentException naming the parameter 'value' is thrown, reporting the value's actual type and the expected PropertyPath type.","triggerScenarios":"Calling TypeConverter.ConvertTo (or a serializer/XAML writer that uses it) with a value that is null or not a System.Windows.PropertyPath instance, e.g. passing a raw string instead of a PropertyPath.","commonSituations":"Serializing objects for designer tools or XAML writers where a property is expected to hold a PropertyPath but holds a string or other type; reflection-based code paths that bypass PropertyPathConverter.ConvertFrom (which would have created a PropertyPath from a string).","solutions":["Ensure the value passed to ConvertTo is a PropertyPath instance; convert strings first with new PropertyPath(pathString) or PropertyPathConverter.ConvertFrom.","Add a null/type check before calling ConvertTo and skip or convert non-PropertyPath values.","If serializing, register or use a converter appropriate for the actual value type."],"exampleFix":"// before\nconverter.ConvertTo(null, culture, someString, typeof(string));\n// after\nPropertyPath path = someString as string != null ? new PropertyPath((string)someString) : (PropertyPath)someString;\nconverter.ConvertTo(null, culture, path, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (value == null || value is not PropertyPath) throw new ArgumentOutOfRangeException(nameof(value), $\"Expected PropertyPath, got {value?.GetType().Name ?? \"null\"}\");","typeGuard":"bool IsPropertyPath(object value) => value is PropertyPath path && path.PathParameters != null;","tryCatchPattern":"try { return converter.ConvertTo(null, culture, value, destinationType); } catch (ArgumentException ex) when (ex.ParamName == \"value\") { /* fall back to value.ToString() or skip serialization */ }","preventionTips":["Always create PropertyPath instances via new PropertyPath(string) instead of passing raw strings to converters","Null-check and type-check before invoking TypeConverter.ConvertTo","Let XAML serialization go through ConvertFrom first so values are normalized to PropertyPath"],"tags":["wpf","type-converter","argument"],"backgroundTag":"type-mismatch","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"}