SixLabors/ImageSharp · error · ArgumentException
Must not be empty.
Error message
Must not be empty.
What it means
The ImageFrameCollection<TPixel> constructor requires at least one frame because an Image must always contain at least one frame. Passing an empty enumerable of frames violates this invariant and throws ArgumentException. A zero-frame image is not a valid state in ImageSharp.
Solutions
- Ensure at least one ImageFrame<TPixel> is created and added before constructing the collection.
- Guard the frames list: if it is empty after assembly, create a default frame instead of passing an empty list.
- Check the upstream logic that produced the frames collection for accidental emptying.
Example fix
// before
var frames = filteredFrames; // may be empty
var collection = new ImageFrameCollection<Rgba32>(image, frames);
// after
if (frames.Count == 0)
{
frames.Add(new ImageFrame<Rgba32>(configuration, width, height));
}
var collection = new ImageFrameCollection<Rgba32>(image, frames); Defensive patterns
Strategy: validation
Validate before calling
if (frames is null || frames.Count == 0) throw new ArgumentException("At least one frame is required.", nameof(frames)); Type guard
static bool HasFrames(IReadOnlyCollection<ImageFrame<TPixel>> frames) => frames is { Count: > 0 }; Try / catch
try { var collection = new ImageFrameCollection<Rgba32>(image, frames); }
catch (ArgumentException ex) { /* supply a default frame and retry */ } Prevention
- Only construct ImageFrameCollection when frame assembly produced at least one frame.
- Add a default-frame fallback in frame-producing pipelines.
- Test low-level image construction paths with empty collections.
When it happens
Trigger: Constructing ImageFrameCollection<TPixel> (typically via Image load paths or constructor overloads) with an empty IEnumerable<ImageFrame<TPixel>>.
Common situations: Building an image programmatically by assembling frames into a list that ended up empty (e.g. a filtering step removed all frames), or calling a low-level constructor directly with a collection built conditionally.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Cannot detect image format from empty data.
- Cannot remove last frame.
- No encoder was found for extension
- No encoder was found for extension
- The ANI file contains an unsupported frame format.
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/81e51e27085c2376.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/ImageFrameCollection{TPixel}.cs:59
internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames)
{
Guard.NotNull(parent, nameof(parent));
Guard.NotNull(frames, nameof(frames));
this.parent = parent;
// Frames are already cloned by the caller
foreach (ImageFrame<TPixel> f in frames)
{
this.ValidateFrame(f);
this.frames.Add(f);
}
// Ensure at least 1 frame was added to the frames collection
if (this.frames.Count == 0)
{
throw new ArgumentException("Must not be empty.", nameof(frames));
}
}
/// <summary>
/// Gets the number of frames.
/// </summary>
public override int Count => this.frames.Count;
/// <summary>
/// Gets the root frame.
/// </summary>
public new ImageFrame<TPixel> RootFrame
{
get
{
this.EnsureNotDisposed();
// frame collection would always contain at least 1 frameView on GitHub (pinned to 59ce6af6fc)