{"record":{"id":"312685b3e4b0786c","repo":"dotnet/wpf","slug":"sr-format-sr-mustbeoftype-value-dynamicresourceextension","errorCode":null,"errorMessage":"SR.Format(SR.MustBeOfType, \"value\", \"DynamicResourceExtension\")","messagePattern":"SR\\.Format\\(SR\\.MustBeOfType, \"value\", \"DynamicResourceExtension\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DynamicResourceExtensionConverter.cs","lineNumber":47,"sourceCode":"            {\n                return true;\n            }\n            return base.CanConvertTo(context, destinationType);\n        }\n\n        /// <summary>\n        /// Converts to an instance descriptor\n        /// </summary>\n        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType == typeof(InstanceDescriptor))\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                DynamicResourceExtension dynamicResource = value as DynamicResourceExtension;\n\n                if (dynamicResource == null)\n                    throw new ArgumentException(SR.Format(SR.MustBeOfType, \"value\", \"DynamicResourceExtension\"), nameof(value)); \n\n                return new InstanceDescriptor(typeof(DynamicResourceExtension).GetConstructor(new Type[] { typeof(object) }), \n                    new object[] { dynamicResource.ResourceKey } );\n            }\n            return base.ConvertTo(context, culture, value, destinationType);\n        }\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DynamicResourceExtensionConverter.cs#L29-L56","documentation":"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.","triggerScenarios":"Calling TypeConverter.ConvertTo(context, culture, value, destinationType) passing an object that is not DynamicResourceExtension while destinationType is InstanceDescriptor.","commonSituations":"Custom designer/serialization code invoking the converter directly with a wrong object; type confusion when copying property values between resources and setters.","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"],"exampleFix":"// before\nconverter.ConvertTo(ctx, culture, someString, typeof(InstanceDescriptor)); // throws\n// after\nif (value is DynamicResourceExtension)\n    converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor));","handlingStrategy":"type-guard","validationCode":"if (!(value is DynamicResourceExtension)) throw new ArgumentException(nameof(value));","typeGuard":"bool IsDynamicResource(object v) => v is DynamicResourceExtension;","tryCatchPattern":"try { result = converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor)); }\ncatch (ArgumentException ex) when (ex.ParamName == \"value\") { result = null; }","preventionTips":["Verify value types before invoking type converters","Route conversions through the WPF property system rather than calling converters directly"],"tags":["wpf","typeconverter","argument"],"backgroundTag":"type-mismatch","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"}