dotnet/wpf · error · ArgumentException
SR.General_Expected_Type
Error message
SR.General_Expected_Type
What it means
PathFigureCollectionConverter.CanConvertTo throws ArgumentException with SR.General_Expected_Type when the serialization context supplies an Instance that is not a PathFigureCollection. The converter only supports converting to string for actual PathFigureCollection instances.
Solutions
- Pass a context whose Instance is a PathFigureCollection.
- Check context.Instance is PathFigureCollection before invoking the converter and return false otherwise.
- Use the correct TypeConverter for the object type being serialized.
Example fix
// before bool ok = converter.CanConvertTo(context, typeof(string)); // context.Instance is not a PathFigureCollection // after bool ok = context?.Instance is PathFigureCollection && converter.CanConvertTo(context, typeof(string));
Defensive patterns
Strategy: type-guard
Validate before calling
if (context?.Instance is PathFigureCollection)
return converter.CanConvertTo(context, destinationType);
return false; Type guard
context?.Instance is PathFigureCollection collection
Try / catch
try
{
return converter.CanConvertTo(context, typeof(string));
}
catch (ArgumentException)
{
return false; // context.Instance was not a PathFigureCollection
} Prevention
- Only pass type-descriptor contexts whose Instance matches the converter's target type.
- Use TypeDescriptor.GetConverter(instance) to obtain the correct converter automatically.
When it happens
Trigger: Calling CanConvertTo(context, typeof(string)) with an ITypeDescriptorContext whose Instance property holds an object of a different type.
Common situations: Reusing the converter manually with a mismatched context instance; designer/serialization pipelines passing the wrong object as context.Instance; custom TypeDescriptor setups wiring this converter to another type.
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.General_BadType, "ConvertFrom")
- SR.Format(SR.MustBeOfType, nameof(value)…
- SR.MustBeOfType
- SR.MustBeOfType: ' ' must be of type ' '. (args: value…
- SR.MustBeOfType: ' ' must be of type ' '. (args: value…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9c7966d6013c0b8b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Generated/PathFigureCollectionConverter.cs:67
/// <summary>
/// Returns true if this type converter can convert to the given type.
/// </summary>
/// <returns>
/// bool - True if this converter can convert to the provided type, false if not.
/// </returns>
/// <param name="context"> The ITypeDescriptorContext for this call. </param>
/// <param name="destinationType"> The Type being queried for support. </param>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
// When invoked by the serialization engine we can convert to string only for some instances
if (context != null && context.Instance != null)
{
if (!(context.Instance is PathFigureCollection))
{
throw new ArgumentException(SR.Format(SR.General_Expected_Type, "PathFigureCollection"), nameof(context));
}
PathFigureCollection value = (PathFigureCollection)context.Instance;
return value.CanSerializeToString();
}
return true;
}
return base.CanConvertTo(context, destinationType);
}
/// <summary>
/// Attempts to convert to a PathFigureCollection from the given object.
/// </summary>
/// <returns>
/// The PathFigureCollection which was constructed.View on GitHub (pinned to 81131a70a4)