SixLabors/ImageSharp · error · InvalidImageContentException
The icon file does not contain any identifiable image…
Error message
The icon file does not contain any identifiable image entries.
What it means
Thrown during icon identification when the directory declares entries but zero frames could be identified from the stream (frameCount is 0), possibly after truncated payload data ended the scan. SixLabors.ImageSharp throws InvalidImageContentException because there is no image information to report for Identify.
Solutions
- Re-download or restore the icon file and retry
- Validate the file: extract each entry at ImageOffset/BytesInRes and check it is a valid PNG/BMP header
- Catch InvalidImageContentException in Identify logic and treat the file as non-image or corrupt
- If truncation is the cause, check the stream length against ImageOffset + BytesInRes of the last entry
Example fix
// before
var info = Image.Identify("icon.ico");
// after
try
{
var info = Image.Identify("icon.ico");
}
catch (InvalidImageContentException)
{
// icon file has no identifiable frames
info = null;
} Defensive patterns
Strategy: try-catch
Validate before calling
// file must at least contain header + one 16-byte entry
static bool PlausibleIcoLength(string path)
{
var b = File.ReadAllBytes(path);
ushort count = (ushort)(b[4] | (b[5] << 8));
return b.Length >= 6 + 16 * count;
} Type guard
static bool IsInvalidImageContent(Exception ex) => ex is InvalidImageContentException;
Try / catch
try
{
var info = Image.Identify(path);
}
catch (InvalidImageContentException)
{
info = null; // no identifiable frames
} Prevention
- Check stream length against declared directory size before identifying
- Re-transfer corrupted files rather than retrying
- Log and quarantine files that repeatedly fail identification
When it happens
Trigger: Calling Image.Identify on an ICO/CUR whose directory entries cannot be identified — corrupt or truncated embedded payloads, or unsupported inner image data; a truncated stream may end before any child payload is parsed.
Common situations: Metadata probing of icon files damaged in transfer; icon files with declared directory entries whose data offsets point at garbage; security/AV tools scanning many potentially corrupt files.
Related errors
- The icon file does not contain any decodable image entries.
- The icon directory header is invalid.
- The icon directory contains an invalid image resource range.
- The embedded icon resource contains an invalid seek offset.
- Not enough bytes to read icon header.
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/f6d263b32876a087.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Icon/IconDecoderCore.cs:242
if (frameCount is 0)
{
bmpMetadata = currentBmpMetadata;
}
}
IconFrameCompression compression = isPng ? IconFrameCompression.Png : IconFrameCompression.Bmp;
this.SetFrameMetadata(metadata, frameMetadata, frameCount, entry, compression, bitsPerPixel, colorTable);
frames[frameCount++] = frameMetadata;
// Identification uses the same embedded-header dimensions as decoding, without allocating pixel buffers.
this.Dimensions = new Size(Math.Max(this.Dimensions.Width, frameInfo.Width), Math.Max(this.Dimensions.Height, frameInfo.Height));
});
}
if (frameCount is 0)
{
throw new InvalidImageContentException("The icon file does not contain any identifiable image entries.");
}
if (frameCount != frames.Length)
{
// Preserve successfully identified frames when truncated image data ends the scan before the declared directory count.
Array.Resize(ref frames, frameCount);
}
// Copy the format specific metadata to the image.
if (bmpMetadata is not null)
{
metadata.SetFormatMetadata(BmpFormat.Instance, bmpMetadata);
}
if (pngMetadata is not null)
{
metadata.SetFormatMetadata(PngFormat.Instance, pngMetadata);
}View on GitHub (pinned to 59ce6af6fc)