{"record":{"id":"81e51e27085c2376","repo":"SixLabors/ImageSharp","slug":"must-not-be-empty","errorCode":null,"errorMessage":"Must not be empty.","messagePattern":"Must not be empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ImageFrameCollection{TPixel}.cs","lineNumber":59,"sourceCode":"\n    internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames)\n    {\n        Guard.NotNull(parent, nameof(parent));\n        Guard.NotNull(frames, nameof(frames));\n\n        this.parent = parent;\n\n        // Frames are already cloned by the caller\n        foreach (ImageFrame<TPixel> f in frames)\n        {\n            this.ValidateFrame(f);\n            this.frames.Add(f);\n        }\n\n        // Ensure at least 1 frame was added to the frames collection\n        if (this.frames.Count == 0)\n        {\n            throw new ArgumentException(\"Must not be empty.\", nameof(frames));\n        }\n    }\n\n    /// <summary>\n    /// Gets the number of frames.\n    /// </summary>\n    public override int Count => this.frames.Count;\n\n    /// <summary>\n    /// Gets the root frame.\n    /// </summary>\n    public new ImageFrame<TPixel> RootFrame\n    {\n        get\n        {\n            this.EnsureNotDisposed();\n\n            // frame collection would always contain at least 1 frame","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ImageFrameCollection{TPixel}.cs#L41-L77","documentation":"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.","triggerScenarios":"Constructing ImageFrameCollection<TPixel> (typically via Image load paths or constructor overloads) with an empty IEnumerable<ImageFrame<TPixel>>.","commonSituations":"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.","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."],"exampleFix":"// before\nvar frames = filteredFrames; // may be empty\nvar collection = new ImageFrameCollection<Rgba32>(image, frames);\n// after\nif (frames.Count == 0)\n{\n    frames.Add(new ImageFrame<Rgba32>(configuration, width, height));\n}\nvar collection = new ImageFrameCollection<Rgba32>(image, frames);","handlingStrategy":"validation","validationCode":"if (frames is null || frames.Count == 0) throw new ArgumentException(\"At least one frame is required.\", nameof(frames));","typeGuard":"static bool HasFrames(IReadOnlyCollection<ImageFrame<TPixel>> frames) => frames is { Count: > 0 };","tryCatchPattern":"try { var collection = new ImageFrameCollection<Rgba32>(image, frames); }\ncatch (ArgumentException ex) { /* supply a default frame and retry */ }","preventionTips":["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."],"tags":["image","frames","argument-validation"],"backgroundTag":"empty-required-field","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"}