{"record":{"id":"77f98ef78e85125a","repo":"dotnet/maui","slug":"cannot-convert-0-into-1","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/ColumnDefinitionCollectionTypeConverter.cs","lineNumber":24,"sourceCode":"using System.Text;\nusing Microsoft.Maui.Controls.Xaml;\n\nnamespace Microsoft.Maui.Controls\n{\n\t/// <summary>Converts a comma-separated string of grid lengths to a <see cref=\"ColumnDefinitionCollection\"/>.</summary>\n\t[ProvideCompiled(\"Microsoft.Maui.Controls.XamlC.ColumnDefinitionCollectionTypeConverter\")]\n\tpublic class ColumnDefinitionCollectionTypeConverter : 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 as string ?? value?.ToString()\n\t\t\t\t?? throw new InvalidOperationException(string.Format(\"Cannot convert \\\"{0}\\\" into {1}\", value, typeof(ColumnDefinitionCollection)));\n\n\t\t\t// fast path for no value or empty string\n\t\t\tif (strValue.Length == 0)\n\t\t\t\treturn new ColumnDefinitionCollection();\n\n#if NET6_0_OR_GREATER\n\t\t\tvar unsplit = (ReadOnlySpan<char>)strValue;\n\t\t\tvar count = unsplit.Count(',') + 1;\n\t\t\tvar definitions = new List<ColumnDefinition>(count);\n\t\t\tforeach (var range in unsplit.Split(','))\n\t\t\t{\n\t\t\t\tvar length = Converters.GridLengthTypeConverter.ParseStringToGridLength(unsplit[range]);\n\t\t\t\tdefinitions.Add(new ColumnDefinition(length));\n\t\t\t}\n#else\n\t\t\tvar lengths = strValue.Split(',');\n\t\t\tvar count = lengths.Length;\n\t\t\tvar definitions = new List<ColumnDefinition>(count);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/ColumnDefinitionCollectionTypeConverter.cs#L6-L42","documentation":"Thrown by ColumnDefinitionCollectionTypeConverter.ConvertFrom when the incoming value is null or cannot be coerced to a string. The converter expects a comma-separated list of GridLength values (e.g. \"*,Auto,100\"); a null input has no string representation.","triggerScenarios":"Passing null or a non-string object whose ToString() is null to the converter. A XAML ColumnDefinitions attribute bound to a source that evaluates to null. Programmatic ConvertFrom(null) calls.","commonSituations":"Binding ColumnDefinitions to a nullable property that becomes null. Missing XAML attribute resolved through the converter. Deserialization dropping the value.","solutions":["Provide a valid comma-separated GridLength string (e.g. \"*,Auto\").","Guard the source so it never yields null.","Use a default ColumnDefinitionCollection when the input is unavailable."],"exampleFix":"// before\nvar cols = (ColumnDefinitionCollection)\n    new ColumnDefinitionCollectionTypeConverter().ConvertFrom(null);\n\n// after\ngrid.ColumnDefinitions = new ColumnDefinitionCollection\n{\n    new ColumnDefinition(GridLength.Star),\n    new ColumnDefinition(GridLength.Auto)\n};","handlingStrategy":"validation","validationCode":"if (value is null || value.ToString() is null)\n    return new ColumnDefinitionCollection(); // or throw with context\n// proceed with converter","typeGuard":"static bool IsValidColumnDefinitions(object v) =>\n    v is string s && s.Length > 0;","tryCatchPattern":null,"preventionTips":["Provide a non-null comma-separated GridLength string.","Guard bound sources against null.","Use a default ColumnDefinitionCollection when input is missing."],"tags":["maui","grid","type-converter","xaml","null"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}