dotnet/wpf · error · ArgumentException
SR.Format(SR.UnexpectedParameterType, value.GetType()…
Error message
SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PropertyPath))
What it means
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.
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.
Example fix
// before converter.ConvertTo(null, culture, someString, typeof(string)); // after PropertyPath path = someString as string != null ? new PropertyPath((string)someString) : (PropertyPath)someString; converter.ConvertTo(null, culture, path, typeof(string));
Defensive patterns
Strategy: type-guard
Validate before calling
if (value == null || value is not PropertyPath) throw new ArgumentOutOfRangeException(nameof(value), $"Expected PropertyPath, got {value?.GetType().Name ?? "null"}"); Type guard
bool IsPropertyPath(object value) => value is PropertyPath path && path.PathParameters != null;
Try / catch
try { return converter.ConvertTo(null, culture, value, destinationType); } catch (ArgumentException ex) when (ex.ParamName == "value") { /* fall back to value.ToString() or skip serialization */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- SR.Format(SR.MustBeOfType, nameof(value)…
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
- SR.MustBeOfType
- SR.MustBeOfType: ' ' must be of type ' '. (args: value…
- " }} " element found. Expected fixed page element ( }} ).
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/568c3c91d8db195d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPathConverter.cs:139
/// <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;
XamlDesignerSerializationManager manager = typeDescriptorContext == null ?
null :
typeDescriptorContext.GetService(typeof(XamlDesignerSerializationManager)) as XamlDesignerSerializationManager;
ValueSerializer typeSerializer = null;
IValueSerializerContext serializerContext = null;
if (manager == null)View on GitHub (pinned to 81131a70a4)