{"record":{"id":"4ebf1846e729ccf0","repo":"SixLabors/ImageSharp","slug":"frame-must-have-the-same-dimensions-as-the-image","errorCode":null,"errorMessage":"Frame must have the same dimensions as the image.","messagePattern":"Frame must have the same dimensions as the image\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ImageFrameCollection{TPixel}.cs","lineNumber":399,"sourceCode":"    public IEnumerator<ImageFrame<TPixel>> GetEnumerator()\n    {\n        this.EnsureNotDisposed();\n\n        return this.frames.GetEnumerator();\n    }\n\n    /// <inheritdoc/>\n    IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();\n\n    private void ValidateFrame(ImageFrame<TPixel> frame)\n    {\n        Guard.NotNull(frame, nameof(frame));\n\n        if (this.Count != 0)\n        {\n            if (this.RootFrame.Width != frame.Width || this.RootFrame.Height != frame.Height)\n            {\n                throw new ArgumentException(\"Frame must have the same dimensions as the image.\", nameof(frame));\n            }\n        }\n    }\n\n    /// <inheritdoc/>\n    protected override void Dispose(bool disposing)\n    {\n        if (disposing)\n        {\n            foreach (ImageFrame<TPixel> f in this.frames)\n            {\n                f.Dispose();\n            }\n\n            this.frames.Clear();\n        }\n    }\n","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ImageFrameCollection{TPixel}.cs#L381-L417","documentation":"ImageFrameCollection<TPixel> requires every frame added, inserted, or used to construct the collection to have exactly the same width and height as the root frame. Animation formats in ImageSharp are single-size, so mismatched frame dimensions are rejected with ArgumentException before the frame is stored.","triggerScenarios":"Calling AddFrame/InsertFrame (or the ImageFrameCollection constructor) with an ImageFrame<TPixel> whose Width/Height differ from RootFrame dimensions.","commonSituations":"Composing an animation from frames decoded at different sizes, or after resizing the root image without resizing all its frames.","solutions":["Resize or clone-resize the frame to the root image dimensions before adding it","Create the frame with new Size(image.Width, image.Height)","Adjust the root image size instead if the new frame's size is the intended one"],"exampleFix":"// before\nimage.Frames.AddFrame(otherFrame);\n// after\nusing ImageFrame<TPixel> resized = otherFrame.Clone(image.Configuration, image.Size);\nimage.Frames.AddFrame(resized);","handlingStrategy":"validation","validationCode":"if (frame.Width != image.Width || frame.Height != image.Height) throw new ArgumentException(\"Frame size mismatch\");","typeGuard":"bool frameMatchesImage<T>(ImageFrame<T> f, Image<T> img) => f.Width == img.Width && f.Height == img.Height;","tryCatchPattern":"try { image.Frames.AddFrame(frame); } catch (ArgumentException ex) when (ex.ParamName == nameof(frame)) { /* resize and retry */ }","preventionTips":["Resize every source frame to the target image size before adding","Clone frames with an explicit Size matching the root frame","After resizing an image, resize all frames, not just the root"],"tags":["csharp","images","frames","dimensions"],"backgroundTag":"shape-mismatch","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"}