{"record":{"id":"60788d70c9fcb981","repo":"dotnet/wpf","slug":"sr-mustbeoftype","errorCode":null,"errorMessage":"SR.MustBeOfType","messagePattern":"SR\\.MustBeOfType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKeyConverter.cs","lineNumber":100,"sourceCode":"        /// <param name=\"culture\">\n        ///     current culture (see CLR specs)\n        /// </param>\n        /// <param name=\"value\">\n        ///     value to convert from\n        /// </param>\n        /// <param name=\"destinationType\">\n        ///     Type to convert to\n        /// </param>\n        /// <returns>\n        ///     converted value\n        /// </returns>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            // Validate Input Arguments\n            ComponentResourceKey key = value as ComponentResourceKey;\n            if (key == null)\n            {\n                throw new ArgumentException(SR.Format(SR.MustBeOfType, \"value\", \"ComponentResourceKey\")); \n            }\n            ArgumentNullException.ThrowIfNull(destinationType);\n            return base.CanConvertTo(context, destinationType);\n        }\n    }\n}\n\n","sourceCodeStart":82,"sourceCodeEnd":108,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ComponentResourceKeyConverter.cs#L82-L108","documentation":"ComponentResourceKeyConverter.ConvertTo validates that the incoming value is a ComponentResourceKey; if it is not (or is null), it throws ArgumentException with the MustBeOfType message. Type converters are invoked by the XAML/designer/type conversion infrastructure, so a wrong-typed value surfaces here.","triggerScenarios":"Calling ConvertTo with a value that is not a ComponentResourceKey (or null), typically via TypeConverter infrastructure or ConvertFromString/ConvertTo pipelines.","commonSituations":"XAML markup extension or designer passing the wrong object into the converter; reflection-driven serialization of a property whose runtime type differs from the declared key type.","solutions":["Ensure the value passed to ConvertTo is a ComponentResourceKey instance","Null-check the value before invoking the converter","Verify the property's declared type matches what you assign"],"exampleFix":"// before\nconverter.ConvertTo(null, culture, someObject, typeof(string)); // throws if someObject isn't a ComponentResourceKey\n// after\nif (someObject is ComponentResourceKey key)\n    converter.ConvertTo(null, culture, key, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (value is not ComponentResourceKey) throw new InvalidOperationException(\"ConvertTo requires a ComponentResourceKey\");","typeGuard":"bool IsComponentResourceKey(object v) => v is ComponentResourceKey;","tryCatchPattern":"try { result = converter.ConvertTo(ctx, culture, value, typeof(string)); } catch (ArgumentException ex) when (ex.ParamName == \"value\") { /* wrong type */ }","preventionTips":["Verify the runtime type before invoking type converters","Null-check converter inputs","Match property declared types with assigned values"],"tags":["wpf","type-converter","argument","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}