{"record":{"id":"b57f827c0ae87b7e","repo":"dotnet/wpf","slug":"sr-mustbeoftype-0-must-be-of-type-1-args-value-b57f82","errorCode":null,"errorMessage":"SR.MustBeOfType: '{0}' must be of type '{1}'. (args: value, TemplateBindingExtension)","messagePattern":"SR\\.MustBeOfType: '(.+?)' must be of type '(.+?)'\\. \\(args: value, TemplateBindingExtension\\)","errorType":"exception","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateBindingExtensionConverter.cs","lineNumber":51,"sourceCode":"            {\n                return true;\n            }\n            return base.CanConvertTo(context, destinationType);\n        }\n\n        /// <summary>\n        /// Converts to an InstanceDescriptor\n        /// </summary>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            if (destinationType == typeof(InstanceDescriptor))\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                TemplateBindingExtension templateBinding = value as TemplateBindingExtension;\n\n                if(templateBinding == null)\n                    throw new ArgumentException(SR.Format(SR.MustBeOfType, \"value\", \"TemplateBindingExtension\"), nameof(value));\n\n                return new InstanceDescriptor(typeof(TemplateBindingExtension).GetConstructor(new Type[] { typeof(DependencyProperty) }),\n                    new object[] { templateBinding.Property });\n            }\n            return base.ConvertTo(context, culture, value, destinationType);\n        }\n\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateBindingExtensionConverter.cs#L33-L61","documentation":"TemplateBindingExtensionConverter.ConvertTo produces an InstanceDescriptor for serialization and requires the value to be a TemplateBindingExtension. Any other value (including null) triggers ArgumentNullException or ArgumentException (SR.MustBeOfType) naming the 'value' parameter.","triggerScenarios":"Calling ConvertTo with a destinationType of InstanceDescriptor but a value that is not a TemplateBindingExtension; also ConvertTo(null, ...) which trips ArgumentNullException.ThrowIfNull(value).","commonSituations":"Serialization/designer tooling invoking the converter with wrong-typed input; code mistaking TemplateBindingExpression for TemplateBindingExtension.","solutions":["Pass a TemplateBindingExtension instance with a valid Property to ConvertTo.","Type-check (is TemplateBindingExtension) before invoking the converter.","Use the correct converter for other markup extension types rather than routing everything through this one."],"exampleFix":"// before\nconverter.ConvertTo(context, culture, expression, typeof(InstanceDescriptor));\n// after\nif (expression is TemplateBindingExtension ext)\n    converter.ConvertTo(context, culture, ext, typeof(InstanceDescriptor));","handlingStrategy":"type-guard","validationCode":"if (value is not TemplateBindingExtension) throw new ArgumentException(\"value must be TemplateBindingExtension\", nameof(value));","typeGuard":"static bool IsTemplateBindingExtension(object v) => v is TemplateBindingExtension;","tryCatchPattern":"try { result = converter.ConvertTo(ctx, culture, value, typeof(InstanceDescriptor)); }\ncatch (ArgumentException ex) { log(ex.ParamName); result = null; }","preventionTips":["Don't confuse TemplateBindingExpression with TemplateBindingExtension","Null-check before ConvertTo","Route each markup extension type to its own converter"],"tags":["wpf","type-converter","serialization","type-mismatch"],"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"}