dotnet/wpf · error · ArgumentException
SR.Format(SR.CannotConvertType, typeof(PropertyPath)…
Error message
SR.Format(SR.CannotConvertType, typeof(PropertyPath), destinationType.FullName)
What it means
PropertyPathConverter.ConvertTo throws this ArgumentException when asked to convert a PropertyPath to a destination type other than String. The converter only supports converting to string (the path's Path property); value must also be a PropertyPath, otherwise a separate UnexpectedParameterType error is thrown.
Solutions
- Convert to string: (string)converter.ConvertTo(null, culture, path, typeof(string)), or use path.Path directly
- If a different type is needed, convert to string first and then parse/format that string to the target type
- Fix the caller so destinationType is typeof(string) when handling PropertyPath values
- Guard the call site: only invoke ConvertTo when destinationType == typeof(string)
Example fix
// before var s = (int)converter.ConvertTo(null, null, path, typeof(int)); // throws // after var s = (string)converter.ConvertTo(null, null, path, typeof(string)); // or use the path string directly var s = path.Path;
Defensive patterns
Strategy: type-guard
Validate before calling
bool safe = destinationType == typeof(string) && value is PropertyPath;
if (!safe) { /* use path.Path or a different conversion strategy */ } Type guard
bool CanConvertToString(object v, Type dest) => dest == typeof(string) && v is PropertyPath;
Try / catch
try { var s = converter.ConvertTo(null, culture, path, destinationType); }
catch (ArgumentException ex) when (ex.Message.Contains("Cannot convert")) { s = ((PropertyPath)path).Path; } Prevention
- Only request typeof(string) as the destination for PropertyPath conversion
- Use path.Path directly instead of the converter when you control the code path
- Check destinationType before invoking ConvertTo in generic serialization loops
When it happens
Trigger: Calling ConvertTo(value, typeof(int)) or any non-string destinationType; serialization frameworks requesting a different representation of a PropertyPath; XAML writers requesting unsupported output types in custom scenarios.
Common situations: Custom serializers or designers converting PropertyPath to other types; copying conversion code that assumed general TypeConverter support; automation that converts every property value to its native type rather than string.
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, source.GetType().FullName…
- SR.Format(SR.CannotConvertType, typeof(CornerRadius)…
- Cannot convert from type.
- Converter_ConvertToNotSupported
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0b89d1fe1b4a11bf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs:133
/// An ArgumentException is thrown if the example object is not null and is not a Brush,
/// or if the destinationType isn't one of the valid destination types.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call.
/// If this is null, then no namespace prefixes will be included.</param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The PropertyPath to convert. </param>
/// <param name="destinationType">The type to which to convert the PropertyPath instance. </param>
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext,
CultureInfo cultureInfo,
object value,
Type destinationType)
{
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(destinationType);
if (destinationType != typeof(String))
{
throw new ArgumentException(SR.Format(SR.CannotConvertType, typeof(PropertyPath), destinationType.FullName));
}
PropertyPath path = value as PropertyPath;
if (path == null)
{
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PropertyPath)), nameof(value));
}
if (path.PathParameters.Count == 0)
{
// if the path didn't use paramaters, just write it out as it is
return path.Path;
}
else
{
// if the path used parameters, convert them to (NamespacePrefix:OwnerType.DependencyPropertyName) syntax
string originalPath = path.Path;
Collection<object> parameters = path.PathParameters;View on GitHub (pinned to 81131a70a4)