{"record":{"id":"58d4e38cfffcc1ca","repo":"dotnet/wpf","slug":"sr-format-sr-general-badtype-convertfrom-58d4e3","errorCode":null,"errorMessage":"SR.Format(SR.General_BadType, \"ConvertFrom\")","messagePattern":"SR\\.Format\\(SR\\.General_BadType, \"ConvertFrom\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs","lineNumber":59,"sourceCode":"        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)\n        {\n            return sourceType == typeof(string);\n        }\n\n        /// <summary>\n        /// Converts <paramref name=\"input\"/> of <see langword=\"string\"/> type to its <see cref=\"TextDecorationCollection\"/> representation.\n        /// </summary>\n        /// <param name=\"context\">Context information used for conversion, ignored currently.</param>\n        /// <param name=\"culture\">The culture specifier to use, ignored currently.</param>        \n        /// <param name=\"input\">The string to convert from.</param>\n        /// <returns>A <see cref=\"TextDecorationCollection\"/> representing the <see langword=\"string\"/> specified by <paramref name=\"input\"/>.</returns>\n        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object input)\n        {\n            if (input is null)\n                throw GetConvertFromException(input);\n\n            if (input is not string value)\n                throw new ArgumentException(SR.Format(SR.General_BadType, \"ConvertFrom\"), nameof(input));\n\n            return ConvertFromString(value);\n        }\n\n        /// <summary>\n        /// Converts <paramref name=\"text\"/> to its <see cref=\"TextDecorationCollection\"/> representation.\n        /// </summary>\n        /// <param name=\"text\">The string to be converted into TextDecorationCollection object.</param>\n        /// <returns>A <see cref=\"TextDecorationCollection\"/> representing the <see cref=\"string\"/> specified by <paramref name=\"text\"/>.</returns>\n        /// <remarks>\n        /// The text parameter can be either be <see langword=\"null\"/>; <see cref=\"string.Empty\"/>; the string \"None\"\n        /// or a combination of the predefined <see cref=\"TextDecorations\"/> names delimited by commas (,).\n        /// One or more blanks spaces can precede  or follow each text decoration name or comma.\n        /// There can't be duplicate TextDecoration names in the string. The operation is case-insensitive. \n        /// </remarks>\n        public static new TextDecorationCollection ConvertFromString(string text)\n        {\n            if (text is null)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/TextDecorationCollectionConverter.cs#L41-L77","documentation":"TextDecorationCollectionConverter.ConvertFrom throws an ArgumentException (SR.General_BadType for \"ConvertFrom\") when the input object is neither null nor a string. The converter only supports string input (or null, which produces a different GetConvertFromException).","triggerScenarios":"Passing a non-string (e.g. an array, int, or TextDecorationCollection itself) to ConvertFrom / TypeDescriptor.ConvertFrom on TextDecorationCollectionConverter.","commonSituations":"XAML or designer value conversion pipelines feeding raw objects; reflection-based conversion helpers assuming broader input support.","solutions":["Pass a string like \"underline\" or \"strikethrough,overline\" to the converter.","If you already have a TextDecorationCollection, use it directly instead of converting.","Use ConvertFromString rather than ConvertFrom for string sources."],"exampleFix":"// before\nconverter.ConvertFrom(context, culture, new object[] { \"underline\" });\n// after\nconverter.ConvertFrom(context, culture, \"underline\");","handlingStrategy":"type-guard","validationCode":"if (input is not string s) throw new ArgumentException(\"TextDecorationCollectionConverter accepts only string input\", nameof(input));","typeGuard":"bool IsConvertibleToString(object? v) => v is string;","tryCatchPattern":"try { result = converter.ConvertFrom(context, culture, input); } catch (ArgumentException) { /* handle non-string input */ }","preventionTips":["Only call the converter with string values","Check input.GetType() before ConvertFrom","Use ConvertFromString for string sources"],"tags":["wpf","type-converter","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-22T01:17:13.364Z"}