SixLabors/ImageSharp · error · UnknownImageFormatException

No encoder was found for extension

Error message

No encoder was found for extension '{ext}'. Registered encoders include:

What it means

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.

Solutions

  1. Use a supported extension matching a registered format (png, jpg, jpeg, bmp, gif, webp, etc.)
  2. Register the custom format: configuration.Configure(new MyImageFormat()) before saving
  3. Explicitly specify an encoder instead of relying on extension detection: image.Save(path, new JpegEncoder())
  4. Check the error message's list of registered encoders to see which extensions are valid

Example fix

// before
image.Save("output.xyz");
// after
image.Save("output.png"); // or image.Save("output.xyz", new PngEncoder());
Defensive patterns

Strategy: validation

Validate before calling

string ext = Path.GetExtension(path);
var known = configuration.ImageFormats
    .SelectMany(f => f.FileExtensions, (f, e) => e)
    .ToHashSet(StringComparer.OrdinalIgnoreCase);
if (!known.Contains(ext.TrimStart('.'))) throw new ArgumentException($"Unsupported extension: {ext}");

Type guard

bool IsSupportedExtension(Configuration cfg, string path) =>
    cfg.ImageFormats.SelectMany(f => f.FileExtensions)
       .Contains(Path.GetExtension(path).TrimStart('.'), StringComparer.OrdinalIgnoreCase);

Try / catch

try { image.Save(path); }
catch (UnknownImageFormatException ex) { logger.LogError(ex, "No encoder for {Path}", path); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/959f692811255b05. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Advanced/AdvancedImageExtensions.cs:39

    /// <param name="filePath">The target file path to save the image to.</param>
    /// <returns>The matching <see cref="IImageEncoder"/>.</returns>
    /// <exception cref="ArgumentNullException">The file path is null.</exception>
    /// <exception cref="UnknownImageFormatException">No encoder available for provided path.</exception>
    public static IImageEncoder DetectEncoder(this Image source, string filePath)
    {
        Guard.NotNull(filePath, nameof(filePath));

        string ext = Path.GetExtension(filePath);
        if (!source.Configuration.ImageFormatsManager.TryFindFormatByFileExtension(ext, out IImageFormat? format))
        {
            StringBuilder sb = new();
            sb = sb.AppendLine(CultureInfo.InvariantCulture, $"No encoder was found for extension '{ext}'. Registered encoders include:");
            foreach (IImageFormat fmt in source.Configuration.ImageFormats)
            {
                sb = sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", fmt.Name, string.Join(", ", fmt.FileExtensions), Environment.NewLine);
            }

            throw new UnknownImageFormatException(sb.ToString());
        }

        IImageEncoder? encoder = source.Configuration.ImageFormatsManager.GetEncoder(format);

        if (encoder is null)
        {
            StringBuilder sb = new();
            sb = sb.AppendLine(CultureInfo.InvariantCulture, $"No encoder was found for extension '{ext}' using image format '{format.Name}'. Registered encoders include:");
            foreach (KeyValuePair<IImageFormat, IImageEncoder> enc in source.Configuration.ImageFormatsManager.ImageEncoders)
            {
                sb = sb.AppendFormat(CultureInfo.InvariantCulture, " - {0} : {1}{2}", enc.Key, enc.Value.GetType().Name, Environment.NewLine);
            }

            throw new UnknownImageFormatException(sb.ToString());
        }

        return encoder;
    }

View on GitHub (pinned to 59ce6af6fc)