{"record":{"id":"0dc9104cd670d14c","repo":"dotnet/machinelearning","slug":"saving-image-with-the-format-ext-is-not-suppor","errorCode":null,"errorMessage":"Saving image with the format '{ext}' is not supported. Try save it with `Jpeg`, `Png`, or `Webp` format.","messagePattern":"Saving image with the format '(.+?)' is not supported\\. Try save it with `Jpeg`, `Png`, or `Webp` format\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.ImageAnalytics/MLImage.cs","lineNumber":246,"sourceCode":"        /// <summary>\n        /// Save the current image to a file.\n        /// </summary>\n        /// <param name=\"imagePath\">The path of the file to save the image to.</param>\n        /// <remarks>The saved image encoding will be detected from the file extension.</remarks>\n        public void Save(string imagePath)\n        {\n            ThrowInvalidOperationExceptionIfDisposed();\n            string ext = Path.GetExtension(imagePath);\n\n            if (!_extensionToEncodingFormat.TryGetValue(ext, out SKEncodedImageFormat encodingFormat))\n            {\n                throw new ArgumentException($\"Path has invalid image file extension.\", nameof(imagePath));\n            }\n\n            using SKData data = _image.Encode(encodingFormat, 100);\n            if (data is null)\n            {\n                throw new ArgumentException($\"Saving image with the format '{ext}' is not supported. Try save it with `Jpeg`, `Png`, or `Webp` format.\", nameof(imagePath));\n            }\n\n            using var stream = new FileStream(imagePath, FileMode.Create, FileAccess.Write);\n            data.SaveTo(stream);\n        }\n\n        /// <summary>\n        /// Disposes the image.\n        /// </summary>\n        public void Dispose()\n        {\n            if (_image != null)\n            {\n                _image.Dispose();\n                _image = null;\n            }\n        }\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.ImageAnalytics/MLImage.cs#L228-L264","documentation":"After selecting an encoding format from the extension, Save calls _image.Encode(encodingFormat, 100). If SkiaSharp's encoder returns null for that format, the format is effectively unsupported by the encoder and ArgumentException is thrown.","triggerScenarios":"Calling Save with a recognized extension whose SKImage encode operation returns null — typically when the SkiaSharp build lacks the encoder for that format.","commonSituations":"Rare encoder-availability differences across platforms/SkiaSharp versions; mostly avoided by sticking to JPEG, PNG, or WebP.","solutions":["Save as Jpeg, Png, or Webp as the message suggests","Update the SkiaSharp native assets to a build that includes the needed encoder","Catch ArgumentException and retry with a .png path"],"exampleFix":"// before\nimage.Save(\"out.webp\"); // encoder returned null\n// after\ntry { image.Save(\"out.webp\"); } catch (ArgumentException) { image.Save(\"out.png\"); }","handlingStrategy":"fallback","validationCode":"// no pre-call API surface; prefer known-good formats\nstring ext = Path.GetExtension(path).ToLowerInvariant();\nbool knownGood = ext is \".jpg\" or \".jpeg\" or \".png\" or \".webp\";","typeGuard":null,"tryCatchPattern":"try { image.Save(path); } catch (ArgumentException ex) when (ex.Message.Contains(\"is not supported\")) { image.Save(Path.ChangeExtension(path, \".png\")); }","preventionTips":["Stick to JPEG, PNG, or WebP output formats","Keep SkiaSharp native assets up to date","Provide a PNG fallback path in save logic"],"tags":["csharp","image","encoding"],"backgroundTag":"unsupported-operation","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}