{"record":{"id":"703169f4c3c6c676","repo":"dotnet/wpf","slug":"sr-tablecollectionwrongproxyparent","errorCode":null,"errorMessage":"SR.TableCollectionWrongProxyParent","messagePattern":"SR\\.TableCollectionWrongProxyParent","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs","lineNumber":143,"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, TableColumn item)\n        {\n            Debug.Assert(item != null && item.Index == -1);\n            Debug.Assert(Items[index] == null);\n\n            // If the TItem 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            else\n            {\n                if (item.Parent != null)\n                {\n                    throw new System.ArgumentException(SR.TableCollectionInOtherCollection);\n                }\n\n                Owner.AddLogicalChild(item);\n            }\n\n            // add the item into collection's array\n            Items[index] = item;\n            item.Index = index;\n\n            // notify the TItem about the change\n            item.OnEnterParentTree();","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs#L125-L161","documentation":"When a TableColumn is parented through a DummyProxy in the logical tree, PrivateConnectChild verifies that the proxy's logical parent is this collection's Owner table. If not, the item is already parented to a different table through its proxy and an ArgumentException (SR.TableCollectionWrongProxyParent) is thrown — a TableColumn cannot belong to two tables.","triggerScenarios":"Adding/Inserting a TableColumn (or constructing the collection with it) whose Parent is a DummyProxy whose logical parent is a different Table than the collection's Owner.","commonSituations":"Moving a column from one Table to another without removing it from the first; sharing column instances across multiple tables; copying table templates that reuse the same TableColumn objects.","solutions":["Remove the column from its current table's collection before adding it to another","Create a new TableColumn instance for the second table instead of reusing one","If the proxy parent is the correct table, ensure the collection's Owner matches (use the right table's collection)"],"exampleFix":"// before\notherTable.Columns.Add(sharedColumn);\n// after\ncurrentTable.Columns.Remove(sharedColumn);\notherTable.Columns.Add(sharedColumn);","handlingStrategy":"validation","validationCode":"if (col.Parent != null && col.Parent is not DummyProxy) throw new InvalidOperationException(\"Column already parented.\");","typeGuard":null,"tryCatchPattern":"try { table.Columns.Add(col); } catch (ArgumentException) { previousTable.Columns.Remove(col); table.Columns.Add(col); }","preventionTips":["Never share TableColumn instances between tables","Remove a column from its current table before reparenting","Clone columns when duplicating table layouts"],"tags":["wpf","tables","logical-tree","argument","collections"],"backgroundTag":"invalid-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}