{"record":{"id":"a6a3dc88a90635a6","repo":"dotnet/maui","slug":"cannot-convert-0-into-1-a6a3dc","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/FileImageSourceConverter.cs","lineNumber":22,"sourceCode":"\nnamespace Microsoft.Maui.Controls\n{\n\t/// <summary>A <see cref=\"System.ComponentModel.TypeConverter\"/> that converts to <see cref=\"Microsoft.Maui.Controls.FileImageSource\"/>.</summary>\n\tpublic sealed class FileImageSourceConverter : 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\t\t\tif (strValue != null)\n\t\t\t\treturn (FileImageSource)ImageSource.FromFile(strValue);\n\n\t\t\tthrow new InvalidOperationException(string.Format(\"Cannot convert \\\"{0}\\\" into {1}\", strValue, typeof(FileImageSource)));\n\t\t}\n\n\t\tpublic override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)\n\t\t{\n\t\t\tif (value is not FileImageSource fis)\n\t\t\t\tthrow new NotSupportedException();\n\t\t\treturn fis.File;\n\t\t}\n\t}\n}\n","sourceCodeStart":4,"sourceCodeEnd":33,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FileImageSourceConverter.cs#L4-L33","documentation":"FileImageSourceConverter.ConvertFrom throws InvalidOperationException when the incoming value is null (so strValue is null). The converter only knows how to build a FileImageSource from a non-null string via ImageSource.FromFile; a null input is treated as an unrecoverable conversion failure rather than producing an empty source.","triggerScenarios":"A XAML binding or TypeConverter path supplies null to a FileImageSource-typed property. Assigning ImageSource via a string converter when the bound model property is null and the converter is invoked (not short-circuited by the binding engine).","commonSituations":"Bound Image.Source to a nullable path whose value is initially null, a design-time preview with no data, or a converter invoked manually with null in tests.","solutions":["Coalesce null before conversion: bind to a fallback path or use TargetNullValue in the Binding.","Avoid invoking the converter directly with null; check the source value first.","Use a default placeholder file path so strValue is never null.","If you call ConvertFrom in code, guard `if (value is null) return null;` first."],"exampleFix":"// before\nvar src = (FileImageSource)new FileImageSourceConverter().ConvertFrom(null);\n\n// after\nif (value is null) return null;\nvar src = (FileImageSource)new FileImageSourceConverter().ConvertFrom(value);","handlingStrategy":"validation","validationCode":"if (value is null) return null; var strValue = value.ToString();","typeGuard":"static bool IsConvertible(object v) => v?.ToString() is not null;","tryCatchPattern":"try { return new FileImageSourceConverter().ConvertFrom(value); } catch (InvalidOperationException) { return null; }","preventionTips":["Bind Image.Source to non-null paths or use TargetNullValue/FallbackValue.","Guard converter invocations against null input in code.","Provide a placeholder file path as the default."],"tags":["maui","typeconverter","imagesource","xaml"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}