{"record":{"id":"959f692811255b05","repo":"SixLabors/ImageSharp","slug":"no-encoder-was-found-for-extension-ext-registered-encoders","errorCode":null,"errorMessage":"No encoder was found for extension '{ext}'. Registered encoders include:","messagePattern":"No encoder was found for extension '(.+?)'\\. Registered encoders include:","errorType":"exception","errorClass":"UnknownImageFormatException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Advanced/AdvancedImageExtensions.cs","lineNumber":39,"sourceCode":"    /// <param name=\"filePath\">The target file path to save the image to.</param>\n    /// <returns>The matching <see cref=\"IImageEncoder\"/>.</returns>\n    /// <exception cref=\"ArgumentNullException\">The file path is null.</exception>\n    /// <exception cref=\"UnknownImageFormatException\">No encoder available for provided path.</exception>\n    public static IImageEncoder DetectEncoder(this Image source, string filePath)\n    {\n        Guard.NotNull(filePath, nameof(filePath));\n\n        string ext = Path.GetExtension(filePath);\n        if (!source.Configuration.ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat? format))\n        {\n            StringBuilder sb = new();\n            sb = sb.AppendLine(CultureInfo.InvariantCulture, $\"No encoder was found for extension '{ext}'. Registered encoders include:\");\n            foreach (IImageFormat fmt in source.Configuration.ImageFormats)\n            {\n                sb = sb.AppendFormat(CultureInfo.InvariantCulture, \" - {0} : {1}{2}\", fmt.Name, string.Join(\", \", fmt.FileExtensions), Environment.NewLine);\n            }\n\n            throw new UnknownImageFormatException(sb.ToString());\n        }\n\n        IImageEncoder? encoder = source.Configuration.ImageFormatsManager.GetEncoder(format);\n\n        if (encoder is null)\n        {\n            StringBuilder sb = new();\n            sb = sb.AppendLine(CultureInfo.InvariantCulture, $\"No encoder was found for extension '{ext}' using image format '{format.Name}'. Registered encoders include:\");\n            foreach (KeyValuePair<IImageFormat, IImageEncoder> enc in source.Configuration.ImageFormatsManager.ImageEncoders)\n            {\n                sb = sb.AppendFormat(CultureInfo.InvariantCulture, \" - {0} : {1}{2}\", enc.Key, enc.Value.GetType().Name, Environment.NewLine);\n            }\n\n            throw new UnknownImageFormatException(sb.ToString());\n        }\n\n        return encoder;\n    }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Advanced/AdvancedImageExtensions.cs#L21-L57","documentation":"ImageSharp could not find any registered IImageEncoder matching the file extension when saving an image via SaveAsXXX-style extension-based dispatch. The library iterates the configuration's ImageFormats, tries to match the extension, and throws UnknownImageFormatException listing every registered format and its extensions so the developer can see what is available.","triggerScenarios":"Calling an extension-based save method like image.SaveAsJpeg/path.Save(...) (e.g. image.Save(\"photo.xyz\")) where the extension 'xyz' does not match the FileExtensions of any format registered in Configuration.ImageFormats.","commonSituations":"Saving with a misspelled or unsupported extension (e.g. .tiff when only Bmp/Jpeg/Png/Gif are registered); a trimmed configuration or custom Configuration built without default formats; using a custom format without registering it via configuration.Configure(new MyFormat()); saving to a temporary path with a wrong extension.","solutions":["Use a supported extension matching a registered format (png, jpg, jpeg, bmp, gif, webp, etc.)","Register the custom format: configuration.Configure(new MyImageFormat()) before saving","Explicitly specify an encoder instead of relying on extension detection: image.Save(path, new JpegEncoder())","Check the error message's list of registered encoders to see which extensions are valid"],"exampleFix":"// before\nimage.Save(\"output.xyz\");\n// after\nimage.Save(\"output.png\"); // or image.Save(\"output.xyz\", new PngEncoder());","handlingStrategy":"validation","validationCode":"string ext = Path.GetExtension(path);\nvar known = configuration.ImageFormats\n    .SelectMany(f => f.FileExtensions, (f, e) => e)\n    .ToHashSet(StringComparer.OrdinalIgnoreCase);\nif (!known.Contains(ext.TrimStart('.'))) throw new ArgumentException($\"Unsupported extension: {ext}\");","typeGuard":"bool IsSupportedExtension(Configuration cfg, string path) =>\n    cfg.ImageFormats.SelectMany(f => f.FileExtensions)\n       .Contains(Path.GetExtension(path).TrimStart('.'), StringComparer.OrdinalIgnoreCase);","tryCatchPattern":"try { image.Save(path); }\ncatch (UnknownImageFormatException ex) { logger.LogError(ex, \"No encoder for {Path}\", path); }","preventionTips":["Keep the default (full) Configuration unless you intentionally trim formats","When adding a custom format, call configuration.Configure(format) which registers format and codecs together","Prefer explicit encoder overloads (image.Save(path, encoder)) in library code"],"tags":["image","format-detection","encoding","argument"],"backgroundTag":"unsupported-operation","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}