{"record":{"id":"97b55c9302ed788d","repo":"SixLabors/ImageSharp","slug":"must-not-be-empty-image-tpixel","errorCode":null,"errorMessage":"Must not be empty.","messagePattern":"Must not be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Image{TPixel}.cs","lineNumber":458,"sourceCode":"    {\n        Guard.NotNull(source, nameof(source));\n\n        this.EnsureNotDisposed();\n\n        ImageFrameCollection<TPixel> sourceFrames = source.Frames;\n        for (int i = 0; i < this.frames.Count; i++)\n        {\n            this.frames[i].CopyMetadataFrom(sourceFrames[i]);\n        }\n\n        this.UpdateMetadata(source.Metadata);\n    }\n\n    private static Size ValidateFramesAndGetSize(IEnumerable<ImageFrame<TPixel>> frames)\n    {\n        Guard.NotNull(frames, nameof(frames));\n\n        ImageFrame<TPixel>? rootFrame = frames.FirstOrDefault() ?? throw new ArgumentException(\"Must not be empty.\", nameof(frames));\n\n        Size rootSize = rootFrame.Size;\n\n        if (frames.Any(f => f.Size != rootSize))\n        {\n            throw new ArgumentException(\"The provided frames must be of the same size.\", nameof(frames));\n        }\n\n        return rootSize;\n    }\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    private void VerifyCoords(int x, int y)\n    {\n        if ((uint)x >= (uint)this.Width)\n        {\n            ThrowArgumentOutOfRangeException(nameof(x));\n        }","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Image{TPixel}.cs#L440-L476","documentation":"The private Image<TPixel>.ValidateFramesAndGetSize uses the first frame of the supplied enumeration to derive the image size, so an empty enumeration has no valid size and yields an unusable image. ImageSharp throws ArgumentException(\"Must not be empty.\") to prevent constructing an image without any frames.","triggerScenarios":"Calling Image.LoadPixelData / new Image<TPixel>(configuration, metadata, frames) or Image.WrapMemory-based constructors with an empty frames collection.","commonSituations":"Filtering a decoded frame list before constructing an image (e.g. dropping all frames) and then passing the empty result; a decoder returning zero frames.","solutions":["Check frames.Count()/Any() before constructing and throw or return early with a clearer message","Guard the source list so at least one frame always survives filtering","Catch ArgumentException around the constructor if frames come from an untrusted source"],"exampleFix":"// before\nvar image = new Image<Rgba32>(config, frames);\n// after\nif (!frames.Any()) throw new InvalidOperationException(\"No frames to build image from.\");\nvar image = new Image<Rgba32>(config, frames);","handlingStrategy":"validation","validationCode":"if (frames is null || !frames.Any()) throw new ArgumentException(\"At least one frame is required.\");","typeGuard":"bool hasFrames<T>(IEnumerable<ImageFrame<T>> frames) => frames != null && frames.Any();","tryCatchPattern":"try { var image = new Image<Rgba32>(config, frames); } catch (ArgumentException ex) when (ex.Message.Contains(\"Must not be empty\")) { /* handle empty input */ }","preventionTips":["Check frame count after any filtering/pipeline step before constructing","Treat decoders returning zero frames as a failure upstream","Never pass collections that may be empty; default to a single blank frame instead"],"tags":["csharp","images","constructor"],"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"}