{"record":{"id":"f4e06e73fdd87a42","repo":"dotnet/maui","slug":"throw-new-notsupportedexception","errorCode":null,"errorMessage":"throw new NotSupportedException();","messagePattern":"throw new NotSupportedException\\(\\);","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FileImageSourceConverter.cs","lineNumber":28,"sourceCode":"\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":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FileImageSourceConverter.cs#L10-L33","documentation":"FileImageSourceConverter.ConvertTo throws a bare NotSupportedException (no message) when the value passed in is not a FileImageSource. The converter only serializes a FileImageSource back to its File string; any other type is unsupported. The lack of a message makes diagnostics harder.","triggerScenarios":"Calling ConvertTo with a StreamImageSource, FontImageSource, UriImageSource, or a non-ImageSource object. XAML round-tripping or serialization pipelines that route mixed ImageSource kinds through one converter.","commonSituations":"Switching an Image source from a file to a URI/font image while a converter-based serializer or property grid still routes through FileImageSourceConverter.","solutions":["Route conversion through the generic ImageSourceConverter or ImageTypeConverter that handles all ImageSource kinds.","Type-check before calling: `if (value is FileImageSource fis) ... else use appropriate converter`.","Avoid ConvertTo for design-time serialization of polymorphic ImageSource values."],"exampleFix":"// before\nvar path = new FileImageSourceConverter().ConvertTo(myUriImageSource, typeof(string));\n\n// after\nif (value is FileImageSource fis)\n    return fis.File;\nthrow new NotSupportedException($\"Expected FileImageSource, got {value?.GetType()}.\");","handlingStrategy":"type-guard","validationCode":"if (value is not FileImageSource) throw new NotSupportedException();","typeGuard":"static bool IsFileImageSource(object v) => v is FileImageSource;","tryCatchPattern":"try { return converter.ConvertTo(value, typeof(string)); } catch (NotSupportedException) { /* route to correct ImageSource converter */ }","preventionTips":["Type-check before invoking ConvertTo on polymorphic ImageSource values.","Use the generic ImageTypeConverter/ImageSourceConverter for mixed kinds.","Avoid serializer round-trips through the file-specific converter."],"tags":["maui","typeconverter","imagesource","diagnostics"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}