{"record":{"id":"d21400e343ebfe04","repo":"dotnet/wpf","slug":"sr-format-sr-general-expected-type-fontfamily","errorCode":null,"errorMessage":"SR.Format(SR.General_Expected_Type, \"FontFamily\")","messagePattern":"SR\\.Format\\(SR\\.General_Expected_Type, \"FontFamily\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamilyConverter.cs","lineNumber":120,"sourceCode":"                    }\n                }\n\n                return new FontFamily(baseUri, s);\n            }\n            return base.ConvertFrom(context, cultureInfo, o);\n        }\n\n        /// <summary>\n        /// ConvertTo - Converts the specified object to an instance of the specified type.\n        /// </summary>\n        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n            FontFamily fontFamily = value as FontFamily;\n            if (fontFamily == null)\n            {\n                throw new ArgumentException(SR.Format(SR.General_Expected_Type, \"FontFamily\"), nameof(value));\n            }\n\n            ArgumentNullException.ThrowIfNull(destinationType);\n\n            if (destinationType == typeof(string))\n            {\n                if (fontFamily.Source != null)\n                {\n                    // Usual case: it's a named font family.\n                    return fontFamily.Source;\n                }\n                else\n                {\n                    // If client calls typeConverter.CanConvertTo(typeof(string)) then we'll return\n                    // true always, even though we don't have access to the FontFamily instance; so\n                    // we need to be able to return some kind of family name even if Source==null.\n                    string name = null;\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamilyConverter.cs#L102-L138","documentation":"FontFamilyConverter.ConvertTo throws this ArgumentException when the value being converted is not a FontFamily instance. The converter only knows how to serialize FontFamily objects (to a string), and rejects any other type by parameter name 'value'.","triggerScenarios":"Calling TypeConverter.ConvertTo(null-context, culture, someNonFontFamilyObject, typeof(string)) — e.g. passing a string, Typeface, or null-derived custom object — expecting it to behave like a FontFamily.","commonSituations":"Generic serialization code piping arbitrary property values through the converter, or binding/converting code that forgot to validate the runtime type.","solutions":["Only call ConvertTo with an actual FontFamily instance (check 'value is FontFamily' first).","Use the correct converter for the value's type (e.g. TypefaceConverter for Typeface).","If converting from string, use ConvertFrom instead."],"exampleFix":"// before\nconverter.ConvertTo(null, culture, \"Arial\", typeof(string));\n// after\nif (value is FontFamily ff)\n    converter.ConvertTo(null, culture, ff, typeof(string));","handlingStrategy":"type-guard","validationCode":"if (value is not FontFamily)\n    throw new ArgumentException(\"value must be a FontFamily\", nameof(value));","typeGuard":"bool IsFontFamily(object v) => v is FontFamily;","tryCatchPattern":"try { var s = (string)converter.ConvertTo(null, culture, value, typeof(string)); }\ncatch (ArgumentException) { /* value wasn't a FontFamily */ }","preventionTips":["Match each value with its correct TypeConverter.","Check 'value is FontFamily' before calling ConvertTo.","Use ConvertFrom for string-to-object conversions."],"tags":["wpf","typeconverter","fonts","argumentexception"],"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"}