{"record":{"id":"18d87cbc7c36ec19","repo":"dotnet/wpf","slug":"sr-format-sr-cannotconverttype-source-gettype-fullname","errorCode":null,"errorMessage":"SR.Format(SR.CannotConvertType, source.GetType().FullName, typeof(PropertyPath))","messagePattern":"SR\\.Format\\(SR\\.CannotConvertType, source\\.GetType\\(\\)\\.FullName, typeof\\(PropertyPath\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs","lineNumber":102,"sourceCode":"        /// <exception cref=\"ArgumentException\">\n        /// An ArgumentException is thrown if the example object is not null and is not a valid type\n        /// which can be converted to a PropertyPath.\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=\"source\"> The object to convert to a PropertyPath. </param>\n        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,\n                                           CultureInfo cultureInfo,\n                                           object source)\n        {\n            ArgumentNullException.ThrowIfNull(source);\n\n            if (source is string)\n            {\n                return new PropertyPath((string)source, typeDescriptorContext);\n            }\n\n            throw new ArgumentException(SR.Format(SR.CannotConvertType, source.GetType().FullName, typeof(PropertyPath)));\n        }\n\n        /// <summary>\n        /// ConvertTo - Attempt to convert a PropertyPath to the given type\n        /// </summary>\n        /// <returns>\n        /// The object which was constructed.\n        /// </returns>\n        /// <exception cref=\"ArgumentNullException\">\n        /// An ArgumentNullException is thrown if the example object is null.\n        /// </exception>\n        /// <exception cref=\"ArgumentException\">\n        /// An ArgumentException is thrown if the example object is not null and is not a Brush,\n        /// or if the destinationType isn't one of the valid destination types.\n        /// </exception>\n        /// <param name=\"typeDescriptorContext\"> The ITypeDescriptorContext for this call.\n        ///  If this is null, then no namespace prefixes will be included.</param>\n        /// <param name=\"cultureInfo\"> The CultureInfo which is respected when converting. </param>","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs#L84-L120","documentation":"PropertyPathConverter.ConvertFrom throws this ArgumentException when the source value is neither null, a string, nor already a PropertyPath. The converter only supports converting from string (or passing through PropertyPath); any other source type cannot be converted to PropertyPath, so the request is rejected.","triggerScenarios":"TypeConverter.ConvertFrom called with an int, Uri, Binding, or other non-string object; XAML or data-binding infrastructure feeding a non-string attribute value into a property typed as PropertyPath; programmatic conversion of arbitrary objects to PropertyPath.","commonSituations":"Passing a non-string value in XAML where a path string was expected (missing quotes or wrong element); calling converter.ConvertFrom directly in custom markup extensions; refactors changing a property type from string to PropertyPath while callers still pass typed values.","solutions":["Pass the path as a string: converter.ConvertFrom(null, culture, \"Customer.Orders\") or construct new PropertyPath(\"...\") directly","If the value is already a PropertyPath, use it as-is instead of re-converting","Check the source object's type before conversion and convert it to string (e.g. ToString or Uri.ToString) first","Fix the XAML/binding call site so a string literal is supplied for the path attribute"],"exampleFix":"// before\nobject src = new Uri(\"Customer.Orders\");\nvar path = (PropertyPath)converter.ConvertFrom(null, null, src); // throws\n// after\nvar path = (PropertyPath)converter.ConvertFrom(null, null, \"Customer.Orders\");\n// or\nvar path = new PropertyPath(\"Customer.Orders\");","handlingStrategy":"type-guard","validationCode":"bool convertible = source is string || source is PropertyPath || source == null;\nif (!convertible) source = source?.ToString(); // pre-normalize to string","typeGuard":"bool CanConvertToPropertyPath(object o) => o is string || o is PropertyPath || o == null;","tryCatchPattern":"try { var path = (PropertyPath)converter.ConvertFrom(null, culture, source); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Cannot convert\")) { /* fall back to new PropertyPath(source?.ToString()) */ }","preventionTips":["Only feed strings (or existing PropertyPath instances) to PropertyPathConverter","Prefer the PropertyPath constructor directly over the converter in code","Quote path values properly in XAML so they arrive as strings"],"tags":["wpf","typeconverter","property-path","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-21T21:30:21.729Z"}