dotnet/wpf · error · ArgumentException
SR.Format(SR.MustBeOfType, "value"…
Error message
SR.Format(SR.MustBeOfType, "value", "DynamicResourceExtension")
What it means
DynamicResourceExtensionConverter.ConvertTo converts a DynamicResourceExtension to an InstanceDescriptor (for designer serialization). It throws ArgumentException with MustBeOfType when the supplied value is not a DynamicResourceExtension instance.
Solutions
- Ensure the value passed to ConvertTo is a DynamicResourceExtension instance
- Check the value type before converting
- Use the converter only through the property system/designer pipeline, which supplies the correct types
Example fix
// before
converter.ConvertTo(ctx, culture, someString, typeof(InstanceDescriptor)); // throws
// after
if (value is DynamicResourceExtension)
converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor)); Defensive patterns
Strategy: type-guard
Validate before calling
if (!(value is DynamicResourceExtension)) throw new ArgumentException(nameof(value));
Type guard
bool IsDynamicResource(object v) => v is DynamicResourceExtension;
Try / catch
try { result = converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor)); }
catch (ArgumentException ex) when (ex.ParamName == "value") { result = null; } Prevention
- Verify value types before invoking type converters
- Route conversions through the WPF property system rather than calling converters directly
When it happens
Trigger: Calling TypeConverter.ConvertTo(context, culture, value, destinationType) passing an object that is not DynamicResourceExtension while destinationType is InstanceDescriptor.
Common situations: Custom designer/serialization code invoking the converter directly with a wrong object; type confusion when copying property values between resources and setters.
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.CannotConvertType, typeof(CornerRadius)…
- SR.Format(SR.General_BadType, "ConvertFrom")
- SR.Format(SR.General_Expected_Type, nameof(PixelFormat))
- SR.Format(SR.UnexpectedParameterType, value.GetType()…
- 'value' must be of type 'BitmapSource'.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/312685b3e4b0786c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DynamicResourceExtensionConverter.cs:47
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
/// <summary>
/// Converts to an instance descriptor
/// </summary>
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
ArgumentNullException.ThrowIfNull(value);
DynamicResourceExtension dynamicResource = value as DynamicResourceExtension;
if (dynamicResource == null)
throw new ArgumentException(SR.Format(SR.MustBeOfType, "value", "DynamicResourceExtension"), nameof(value));
return new InstanceDescriptor(typeof(DynamicResourceExtension).GetConstructor(new Type[] { typeof(object) }),
new object[] { dynamicResource.ResourceKey } );
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
View on GitHub (pinned to 81131a70a4)