SixLabors/ImageSharp · error · InvalidImageContentException
Unable to read Gif image data
Error message
Unable to read Gif image data
What it means
Thrown when a GIF signature was recognized but no image data follows — the decoder found a header yet no Image Descriptor or blocks. Raised as InvalidImageContentException to report that the GIF body is empty.
Solutions
- Regenerate the GIF ensuring at least one image block is written
- Check the producing pipeline — an empty animation export commonly causes this
- Validate minimum file size / presence of an image descriptor before decoding
- Catch InvalidImageContentException and treat the asset as invalid in your ingest pipeline
Example fix
// before
var image = Image.Load(stream);
// after
try { var image = Image.Load(stream); }
catch (InvalidImageContentException ex) when (ex.Message.Contains("image data")) { MarkAssetInvalid(assetId); } Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the GIF has at least one image descriptor (0x2C) after the header
byte[] all = File.ReadAllBytes(path);
bool hasImageBlock = all.AsSpan(13).IndexOf((byte)0x2C) >= 0;
if (!hasImageBlock) throw new InvalidDataException("GIF contains no image data");
Try / catch
try { return Image.Load(stream); }
catch (InvalidImageContentException ex) when (ex.Message.Contains("Unable to read Gif image data")) { return RegenerateOrSkip(stream); } Prevention
- Reject 0-frame GIFs at export time in your pipeline
- Validate GIFs with magick identify during ingest
- Regenerate placeholder GIFs that contain only extensions
- Keep the generating toolchain updated
When it happens
Trigger: Image.Load/Decode on a file that begins with a valid GIF header+screen descriptor but ends (or contains only extensions) before any image data block.
Common situations: Empty/placeholder GIFs created by buggy tools, files truncated right after the header, or assets uploaded as 0-image GIFs from a broken pipeline.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- Gif image does not contain a Logical Screen Descriptor.
- Invalid EXR image header
- Unexpected end of stream while reading gif application…
- Invalid gif colormap size
- The ANI file does not contain any frame resources.
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/aa8804970a2b58fa.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Gif/GifThrowHelper.cs:18
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
namespace SixLabors.ImageSharp.Formats.Gif;
internal static class GifThrowHelper
{
[DoesNotReturn]
public static void ThrowInvalidImageContentException(string errorMessage)
=> throw new InvalidImageContentException(errorMessage);
[DoesNotReturn]
public static void ThrowNoHeader() => throw new InvalidImageContentException("Gif image does not contain a Logical Screen Descriptor.");
[DoesNotReturn]
public static void ThrowNoData() => throw new InvalidImageContentException("Unable to read Gif image data");
}
View on GitHub (pinned to 59ce6af6fc)