{"record":{"id":"484fb367ddb77420","repo":"SixLabors/ImageSharp","slug":"the-provided-frames-must-be-of-the-same-size","errorCode":null,"errorMessage":"The provided frames must be of the same size.","messagePattern":"The provided frames must be of the same size\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Image{TPixel}.cs","lineNumber":464,"sourceCode":"        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        }\n\n        if ((uint)y >= (uint)this.Height)\n        {\n            ThrowArgumentOutOfRangeException(nameof(y));\n        }\n    }","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Image{TPixel}.cs#L446-L482","documentation":"Image<TPixel>.ValidateFramesAndGetSize requires all frames passed to the image constructor to share the same Size as the first frame. Multi-size frame lists cannot back a single Image, so a mismatched list is rejected with ArgumentException.","triggerScenarios":"Constructing an Image<TPixel> from frames with differing Width/Height, e.g. mixing frames from differently sized images or decoders.","commonSituations":"Stitching frames decoded from multiple files or scaled variants into one animation image.","solutions":["Normalize all frames to one size (clone with resize) before constructing the image","Build separate images per size group instead of one combined image","Verify f.Size equals the root frame size before calling the constructor"],"exampleFix":"// before\nvar image = new Image<Rgba32>(config, frames);\n// after\nSize size = frames[0].Size;\nframes = frames.Select(f => f.Size == size ? f : f.Clone(config, size)).ToList();\nvar image = new Image<Rgba32>(config, frames);","handlingStrategy":"validation","validationCode":"if (frames.Any(f => f.Size != frames[0].Size)) throw new ArgumentException(\"Frames must share one size.\");","typeGuard":"bool uniformSize<T>(IReadOnlyList<ImageFrame<T>> frames) => frames.All(f => f.Size == frames[0].Size);","tryCatchPattern":"try { var image = new Image<Rgba32>(config, frames); } catch (ArgumentException ex) when (ex.Message.Contains(\"same size\")) { /* normalize and retry */ }","preventionTips":["Normalize frame sizes immediately after decoding, before storing in a shared list","Group frames by Size and build one image per group","Use a shared Size constant for all frames produced by your pipeline"],"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"}