{"record":{"id":"c35644a3dd42fccb","repo":"CoplayDev/unity-mcp","slug":"unsupported-image-type-ext-for-image-input-us","errorCode":null,"errorMessage":"Unsupported image type '{ext}' for image input. Use .png, .jpg, .jpeg, .webp, or .gif.","messagePattern":"Unsupported image type '(.+?)' for image input\\. Use \\.png, \\.jpg, \\.jpeg, \\.webp, or \\.gif\\.","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Services/AssetGen/Providers/LocalImage.cs","lineNumber":70,"sourceCode":"            if (!AssetGenPaths.TryGetAssetsRelativePath(absPath, out string rel))\n                throw new UnauthorizedAccessException(\"image_path must point to a file under the project's Assets folder.\");\n            absPath = AssetGenPaths.ToAbsolute(rel);\n            string mime = MimeFromExtension(Path.GetExtension(absPath));\n            byte[] bytes = File.ReadAllBytes(absPath);\n            return \"data:\" + mime + \";base64,\" + Convert.ToBase64String(bytes);\n        }\n\n        private static string MimeFromExtension(string ext)\n        {\n            switch ((ext ?? string.Empty).ToLowerInvariant())\n            {\n                case \".png\": return \"image/png\";\n                case \".jpg\":\n                case \".jpeg\": return \"image/jpeg\";\n                case \".webp\": return \"image/webp\";\n                case \".gif\": return \"image/gif\";\n                default:\n                    throw new NotSupportedException(\n                        $\"Unsupported image type '{ext}' for image input. Use .png, .jpg, .jpeg, .webp, or .gif.\");\n            }\n        }\n    }\n}\n","sourceCodeStart":52,"sourceCodeEnd":76,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Services/AssetGen/Providers/LocalImage.cs#L52-L76","documentation":"Thrown by LocalImage.MimeFromExtension (via ToDataUri) when the image file extension is not one of the five supported types: .png, .jpg, .jpeg, .webp, .gif. The switch has no default case that succeeds, so any other extension (or no extension) reaches the default throw. ResolveExisting checks the same set non-throwingly via SupportedExtensions, so the throw indicates ToDataUri was called without that pre-check.","triggerScenarios":"Calling ToDataUri on a file with extension .bmp, .tiff, .tga, .heic, .svg, .exr, .psd, or a file with no extension.","commonSituations":"Unity-native texture formats exported (.tga/.psd/.exr); screenshot saved as .heic on macOS/iOS; an asset with no extension; wrong export preset.","solutions":["Re-export/convert the image to PNG or JPEG (widest provider compatibility).","If you need WebP/GIF animation, ensure the provider accepts that type (all five are accepted for data-URI inlining).","Pre-validate the extension with LocalImage.ResolveExisting before calling ToDataUri."],"exampleFix":"// before\nstring dataUri = LocalImage.ToDataUri(absPath); // throws NotSupportedException for .bmp\n\n// after\nif (!LocalImage.ResolveExisting(req.ImagePath, out string abs, out string err))\n    return ErrorResponse(err); // err names the bad extension\nstring dataUri = LocalImage.ToDataUri(abs);","handlingStrategy":"validation","validationCode":"string ext = System.IO.Path.GetExtension(absPath);\nstring[] ok = {\".png\",\".jpg\",\".jpeg\",\".webp\",\".gif\"};\nif (Array.IndexOf(ok, (ext ?? \"\").ToLowerInvariant()) < 0)\n    return ErrorResponse($\"Unsupported image type '{ext}'. Use .png/.jpg/.jpeg/.webp/.gif.\");","typeGuard":"static readonly HashSet<string> SupportedImageExt =\n    new(StringComparer.OrdinalIgnoreCase){\".png\",\".jpg\",\".jpeg\",\".webp\",\".gif\"};\nstatic bool IsSupportedImage(string path)\n    => SupportedImageExt.Contains(System.IO.Path.GetExtension(path));","tryCatchPattern":"try { string uri = LocalImage.ToDataUri(absPath); }\ncatch (NotSupportedException ex)\n{ /* convert the image to png/jpg, or host it as image_url */ }","preventionTips":["Pre-validate the extension with LocalImage.ResolveExisting, which checks SupportedExtensions.","Standardize input images on PNG/JPEG for the widest provider support.","Reject .bmp/.tga/.psd/.heic at the tool boundary with a clear message."],"tags":["file-format","image-input","asset-gen","validation"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}