{"record":{"id":"55570f180d99c338","repo":"dotnet/wpf","slug":"sr-tablecollectionwrongproxyparent-55570f","errorCode":null,"errorMessage":"SR.TableCollectionWrongProxyParent","messagePattern":"SR\\.TableCollectionWrongProxyParent","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableTextElementCollectionInternal.cs","lineNumber":265,"sourceCode":"        /// <exception cref=\"ArgumentException\">\n        /// If the new item has already a parent or if the slot at the specified index is not null.\n        /// </exception>\n        /// <remarks>\n        /// Note that the function requires that _item[index] == null and\n        /// it also requires that the passed in item is not included into another ContentElementCollection.\n        /// </remarks>\n        internal override void PrivateConnectChild(int index, TElementType item)\n        {\n            Debug.Assert(item != null && item.Index == -1);\n            Debug.Assert(Items[index] == null);\n\n            // If the TElementType is already parented correctly through a proxy, there's no need\n            // to change parentage.  Otherwise, it should be parented to Owner.\n            if (item.Parent is DummyProxy)\n            {\n                if (LogicalTreeHelper.GetParent(item.Parent) != Owner)\n                {\n                    throw new System.ArgumentException(SR.TableCollectionWrongProxyParent);\n                }\n            }\n\n            // add the item into collection's array\n            Items[index] = item;\n            item.Index = index;\n\n            // notify the TElementType about the change\n            item.OnEnterParentTree();\n        }\n\n\n        /// <summary>\n        /// Notifies the TItem about the event;\n        /// Disconnects the item from the model tree;\n        /// Sets the TItem's slot in the collection's array to null.\n        /// </summary>\n        internal override void PrivateDisconnectChild(TElementType item)","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableTextElementCollectionInternal.cs#L247-L283","documentation":"When adding an item, PrivateConnectChild checks parentage. If the item's logical Parent is a DummyProxy (a lightweight parent surrogate used by table text element collections), the proxy must resolve through the logical tree to this collection's Owner. If GetParent(item.Parent) != Owner, the item already belongs to a different table/collection and ArgumentException(TableCollectionWrongProxyParent) is thrown.","triggerScenarios":"InternalAdd on an item whose Parent is a DummyProxy owned by another TableTextElementCollectionInternal — i.e. re-parenting a TableRowGroup/TableRow/Run that is already in another table.","commonSituations":"Moving a TableRowGroup from one Table to another without first detaching it; adding an element still referenced by a previous document/collection; sharing a child element between two tables.","solutions":["Detach the item from its current parent first (remove it from the old collection) before adding it here.","Create a new instance instead of reusing an element already parented elsewhere.","Check item.Parent (and logical ancestors) before adding; only add unparented items."],"exampleFix":"// before\nvar row = oldTable.RowGroups[0];\nnewTable.RowGroups.Add(row); // throws\n// after\nvar row = oldTable.RowGroups[0];\noldTable.RowGroups.Remove(row);\nnewTable.RowGroups.Add(row);","handlingStrategy":"validation","validationCode":"if (item.Parent != null && !(item.Parent is DummyProxy && LogicalTreeHelper.GetParent(item.Parent) == owner))\n    throw new InvalidOperationException(\"item is parented to another collection\");","typeGuard":"static bool IsUnparentedOrOwnedBy(this TextElement item, object owner)\n    => item.Parent == null\n       || (item.Parent is DummyProxy && LogicalTreeHelper.GetParent(item.Parent) == owner);","tryCatchPattern":null,"preventionTips":["Always detach elements from their previous parent before re-parenting.","Never share TextElement instances between two tables/documents.","Prefer creating fresh elements over moving existing ones across trees.","Assert item.Parent == null before Add calls in debug builds."],"tags":["wpf","argumentexception","logical-tree","table"],"backgroundTag":"element-already-has-logical-parent","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"}