{"record":{"id":"e299080da3426071","repo":"dotnet/wpf","slug":"sr-drawinggroup-cannotappendtofrozencollection","errorCode":null,"errorMessage":"SR.DrawingGroup_CannotAppendToFrozenCollection","messagePattern":"SR\\.DrawingGroup_CannotAppendToFrozenCollection","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingGroup.cs","lineNumber":122,"sourceCode":"                //\n                //\n                // Append the collection to the current Children collection                \n                //\n                //\n                DrawingCollection children = Children;\n\n                // \n                // Ensure that we can Append to the Children collection\n                //\n                \n                if (children == null)\n                {\n                    throw new InvalidOperationException(SR.DrawingGroup_CannotAppendToNullCollection);                                \n                }\n               \n                if (children.IsFrozen)\n                {\n                    throw new InvalidOperationException(SR.DrawingGroup_CannotAppendToFrozenCollection);                                                  \n                }\n\n                // Append the new collection to our current Children.\n                //\n                // TransactionalAppend rolls-back the Append operation in the event\n                // an exception is thrown from the Changed event.                \n                children.TransactionalAppend(rootDrawingGroupChildren);\n            }            \n\n            // This DrawingGroup is no longer open\n            _open = false;\n        }\n\n        /// <summary>\n        /// Calls methods on the DrawingContext that are equivalent to the\n        /// Drawing with the Drawing's current value.\n        /// </summary>        \n        internal override void WalkCurrentValue(DrawingContextWalker ctx)","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/DrawingGroup.cs#L104-L140","documentation":"DrawingGroup.Close() tried to append the new drawings into a Children collection that is frozen (ImmutableFreezable). Frozen Freezables are read-only by design, so Close throws InvalidOperationException with SR.DrawingGroup_CannotAppendToFrozenCollection.","triggerScenarios":"Calling Close(children) where children.IsFrozen is true — i.e. the DrawingCollection was frozen via Freeze() or was inherited from a frozen/sealed parent DrawingGroup.","commonSituations":"Reusing a frozen template collection across multiple DrawingGroups; cloning a group and trying to reuse its Children; putting a DrawingGroup in a frozen resource dictionary then reopening it.","solutions":["Pass a fresh, unfrozen DrawingCollection to Close","Call collection.Clone() (or GetAsFrozen on a copy) to get a mutable clone before appending","Remove Freeze() calls on collections that will later be reopened","Do not reopen DrawingGroups whose Children live in frozen resources; build a new group instead"],"exampleFix":"// before\nDrawingCollection kids = frozenTemplate.Children; // frozen\nnewGroup.Close(kids); // throws\n\n// after\nvar kids = frozenTemplate.Children.Clone(); // mutable copy\nnewGroup.Close(kids);","handlingStrategy":"validation","validationCode":"if (children != null && children.IsFrozen)\n    children = children.Clone(); // mutable copy\ngroup.Close(children);","typeGuard":null,"tryCatchPattern":"try { group.Close(children); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"frozen\"))\n{\n    group.Close(children.Clone());\n}","preventionTips":["Never Freeze() collections that feed reopenable DrawingGroups","Clone frozen templates before mutation","Treat frozen Freezables as immutable everywhere; copy-on-write instead"],"tags":["wpf","drawinggroup","freezable","frozen-collection"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}