{"record":{"id":"88272a76a20a945b","repo":"dotnet/wpf","slug":"sr-converter-convertfromnotsupported","errorCode":null,"errorMessage":"SR.Converter_ConvertFromNotSupported","messagePattern":"SR\\.Converter_ConvertFromNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySplineConverter.cs","lineNumber":67,"sourceCode":"            else\n            {\n                return false;\n            }\n        }\n\n        /// <summary>\n        /// ConvertFrom\n        /// </summary>\n        public override object ConvertFrom(\n            ITypeDescriptorContext context, \n            CultureInfo cultureInfo, \n            object value)\n        {\n            string stringValue = value as string;\n\n            if (value == null)\n            {\n                throw new NotSupportedException(SR.Converter_ConvertFromNotSupported);\n            }\n\n            TokenizerHelper th = new TokenizerHelper(stringValue, cultureInfo);\n\n            return new KeySpline(\n                Convert.ToDouble(th.NextTokenRequired(), cultureInfo),\n                Convert.ToDouble(th.NextTokenRequired(), cultureInfo),\n                Convert.ToDouble(th.NextTokenRequired(), cultureInfo),\n                Convert.ToDouble(th.NextTokenRequired(), cultureInfo));\n        }\n\n        /// <summary>\n        /// TypeConverter method implementation.\n        /// </summary>\n        /// <param name=\"context\">ITypeDescriptorContext</param>\n        /// <param name=\"cultureInfo\">current culture (see CLR specs), null is a valid value</param>\n        /// <param name=\"value\">value to convert from</param>\n        /// <param name=\"destinationType\">Type to convert to</param>","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySplineConverter.cs#L49-L85","documentation":"KeySplineConverter.ConvertFrom throws NotSupportedException (SR.Converter_ConvertFromNotSupported) when the value argument is null, because the type converter only supports converting string (and KeySpline) input to a KeySpline. Converting from null is explicitly unsupported rather than treated as an empty spline.","triggerScenarios":"TypeDescriptor/Convert.ChangeType style pipelines calling converter.ConvertFrom(context, culture, null), e.g. during XAML or data-binding value conversion when the source value is null.","commonSituations":"XAML attribute bound to a null resource; deserializers invoking type converters for missing fields; code calling KeySplineConverter directly with a null input while assuming default-value semantics.","solutions":["Check for null before calling ConvertFrom and substitute a default KeySpline (e.g. new KeySpline(0,0,1,1)).","In XAML, supply a non-null value or a default in markup rather than relying on the converter.","Use ConvertFromString only for genuine strings; handle null at the caller level.","Catch NotSupportedException and fall back to a default spline if null input is expected in your pipeline."],"exampleFix":"// before\nvar spline = (KeySpline)converter.ConvertFrom(context, culture, possiblyNull);\n// after\nvar spline = possiblyNull == null\n    ? new KeySpline(new Point(0, 0), new Point(1, 1))\n    : (KeySpline)converter.ConvertFrom(context, culture, possiblyNull);","handlingStrategy":"type-guard","validationCode":"if (value == null)\n    return new KeySpline(new Point(0, 0), new Point(1, 1)); // default spline\nvar spline = (KeySpline)converter.ConvertFrom(context, culture, value);","typeGuard":"static bool IsConvertibleValue(object v) => v is string or KeySpline;","tryCatchPattern":"try\n{\n    spline = (KeySpline)converter.ConvertFrom(context, culture, value);\n}\ncatch (NotSupportedException)\n{\n    spline = new KeySpline(new Point(0, 0), new Point(1, 1));\n}","preventionTips":["Null-check converter input before calling ConvertFrom","Coerce nulls to default values at the deserialization layer, not in the converter","In XAML, provide explicit default markup instead of relying on null conversion","Restrict converter calls to string/KeySpline inputs via a wrapper API"],"tags":["wpf","type-converter","null","keyspline"],"backgroundTag":"null-argument","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"}