{"record":{"id":"42b0c2d4cb1206c6","repo":"microsoft/semantic-kernel","slug":"unsupported-image-format","errorCode":null,"errorMessage":"Unsupported image format.","messagePattern":"Unsupported image format\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/Demos/HuggingFaceImageToText/FormMain.cs","lineNumber":192,"sourceCode":"    }\n\n    /// <summary>\n    /// Gets the MIME type of the specific image file extension\n    /// </summary>\n    /// <param name=\"fileName\">The file name with extension</param>\n    /// <returns>The MIME type of the specific image file extension</returns>\n    private static string GetMimeType(string fileName)\n    {\n        return Path.GetExtension(fileName) switch\n        {\n            \".jpg\" or \".jpeg\" => \"image/jpeg\",\n            \".png\" => \"image/png\",\n            \".gif\" => \"image/gif\",\n            \".bmp\" => \"image/bmp\",\n            \".tiff\" => \"image/tiff\",\n            \".ico\" => \"image/x-icon\",\n            \".svg\" => \"image/svg+xml\",\n            _ => throw new NotSupportedException(\"Unsupported image format.\")\n        };\n    }\n\n    private static ImageFormat GetImageFormat(string fileName)\n    {\n        return Path.GetExtension(fileName) switch\n        {\n            \".jpg\" or \".jpeg\" => ImageFormat.Jpeg,\n            \".png\" => ImageFormat.Png,\n            \".gif\" => ImageFormat.Gif,\n            \".bmp\" => ImageFormat.Bmp,\n            \".tiff\" => ImageFormat.Tiff,\n            \".ico\" => ImageFormat.Icon,\n            \".svg\" => ImageFormat.MemoryBmp,\n            _ => throw new NotSupportedException(\"Unsupported image format.\")\n        };\n    }\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/HuggingFaceImageToText/FormMain.cs#L174-L210","documentation":"GetMimeType maps a file extension to a MIME type and throws NotSupportedException for any extension outside jpg/jpeg/png/gif/bmp/tiff/ico/svg. This MIME value is sent to the HuggingFace image-to-text service, so unsupported types can't be submitted. The throw is the catch-all `_` arm of the switch expression.","triggerScenarios":"Path.GetExtension(fileName) returns something not in the supported set — e.g. .webp, .heic, .avif, or an empty/no extension.","commonSituations":"User selects a modern format (webp/avif/heic) the sample doesn't whitelist, or a file with no extension is dropped.","solutions":["Convert the image to one of the supported formats (png/jpg) before loading.","Add the missing extension(s) and their MIME types to the switch if the backend accepts them.","Filter the file picker to allowed extensions so unsupported files can't be selected."],"exampleFix":"// before\n_ => throw new NotSupportedException(\"Unsupported image format.\")\n\n// after\n\".webp\" => \"image/webp\",\n\".avif\" => \"image/avif\",\n_ => throw new NotSupportedException($\"Unsupported image format '{Path.GetExtension(fileName)}'.\")","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> s_supported = new(StringComparer.OrdinalIgnoreCase)\n    { \".jpg\", \".jpeg\", \".png\", \".gif\", \".bmp\", \".tiff\", \".ico\", \".svg\" };\nif (!s_supported.Contains(Path.GetExtension(fileName)))\n    throw new NotSupportedException($\"Unsupported image format '{Path.GetExtension(fileName)}'.\");","typeGuard":"static bool IsSupportedImage(string fileName) =>\n    s_supported.Contains(Path.GetExtension(fileName));","tryCatchPattern":null,"preventionTips":["Constrain the file picker to supported extensions.","Convert modern formats (webp/avif/heic) to png/jpg before loading.","Share the supported-set between GetMimeType and GetImageFormat."],"tags":["image-format","validation","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}