{"record":{"id":"df3052c930e715fe","repo":"dotnet/maui","slug":"cannot-convert-0-into-1-df3052","errorCode":null,"errorMessage":"Cannot convert \"{0}\" into {1}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/DecorableTextElement.cs","lineNumber":28,"sourceCode":"\t\tpublic static readonly BindableProperty TextDecorationsProperty = BindableProperty.Create(nameof(IDecorableTextElement.TextDecorations), typeof(TextDecorations), typeof(IDecorableTextElement), TextDecorations.None);\n\t}\n\n\t/// <summary>A <see cref=\"System.ComponentModel.TypeConverter\"/> subclass that can convert between a string and a <see cref=\"Microsoft.Maui.TextDecorations\"/> object.</summary>\n\tpublic class TextDecorationConverter : TypeConverter\n\t{\n\t\tpublic override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)\n\t\t\t=> sourceType == typeof(string);\n\n\t\tpublic override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)\n\t\t\t=> destinationType == typeof(string);\n\n\t\tpublic override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)\n\t\t{\n\t\t\tvar strValue = value?.ToString();\n\n\t\t\tTextDecorations result = TextDecorations.None;\n\t\t\tif (strValue == null)\n\t\t\t\tthrow new InvalidOperationException(string.Format(\"Cannot convert \\\"{0}\\\" into {1}\", strValue, typeof(TextDecorations)));\n\n\t\t\tvar valueArr = strValue.Split(',');\n\n\t\t\tif (valueArr.Length <= 1)\n\t\t\t\tvalueArr = strValue.Split(' ');\n\n\t\t\tforeach (var item in valueArr)\n\t\t\t{\n\t\t\t\tif (Enum.TryParse(item.Trim(), true, out TextDecorations textDecorations))\n\t\t\t\t\tresult |= textDecorations;\n\t\t\t\telse if (item.Equals(\"line-through\", StringComparison.OrdinalIgnoreCase))\n\t\t\t\t\tresult |= TextDecorations.Strikethrough;\n\t\t\t\telse\n\t\t\t\t\tthrow new InvalidOperationException(string.Format(\"Cannot convert \\\"{0}\\\" into {1}\", item, typeof(TextDecorations)));\n\t\t\t}\n\n\t\t\treturn result;\n\t\t}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/DecorableTextElement.cs#L10-L46","documentation":"The TextDecorationsConverter throws InvalidOperationException when ConvertFrom receives a value whose ToString() is null. Because the converter calls value?.ToString() and then checks for null, this is reached when the source object's ToString returns null — an edge case for null-valued input passed as a non-null object. The message formats the null string and the TextDecorations type.","triggerScenarios":"Passing an object whose ToString() implementation returns null (rare), or passing a null boxed value through a path that boxes it. The strValue==null guard is the only way to reach this throw.","commonSituations":"Custom types overriding ToString to return null; binding a null-valued non-string source to a TextDecorations property via the converter.","solutions":["Pass a string literal or comma/space-separated decoration names (e.g. 'underline', 'strikethrough', 'line-through').","Ensure any custom source object's ToString() never returns null.","Avoid routing null values into TextDecorations properties; use a fallback value."],"exampleFix":"// before\nlabel.TextDecorations = (TextDecorations)converter.ConvertFrom(null, culture, objWithNullToString);\n\n// after\nlabel.TextDecorations = TextDecorations.None; // explicit default","handlingStrategy":"validation","validationCode":"// Avoid passing values whose ToString() is null.\nvar s = value?.ToString();\nif (s is null) throw new ArgumentException(\"value.ToString() returned null; cannot convert to TextDecorations.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass explicit decoration strings, never null-yielding objects.","Ensure custom source types never return null from ToString().","Default unset decorations to TextDecorations.None."],"tags":["typeconverter","textdecorations","convertfrom","invalidoperation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}