{"record":{"id":"97c616173a2589b5","repo":"dotnet/wpf","slug":"sr-tablecollectioninothercollection","errorCode":null,"errorMessage":"SR.TableCollectionInOtherCollection","messagePattern":"SR\\.TableCollectionInOtherCollection","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs","lineNumber":150,"sourceCode":"        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();\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>","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs#L132-L168","documentation":"For a TableColumn that is not parented through a DummyProxy, PrivateConnectChild requires the column to have no parent at all; it then attaches it as a logical child of the Owner table. If item.Parent != null the column already belongs to another parent, and ArgumentException (SR.TableCollectionInOtherCollection) is thrown.","triggerScenarios":"Adding/Inserting a TableColumn whose Parent is neither null nor a DummyProxy — i.e. the column is already in another collection or has a logical parent.","commonSituations":"Reusing a single TableColumn instance across two tables; moving columns between tables without removal; binding the same column collection instance to multiple tables.","solutions":["Remove the column from its previous collection (or clear its logical parent) before adding it here","Clone or construct a fresh TableColumn per table","Audit shared column resources (styles/templates) so only the column object is per-table"],"exampleFix":"// before\ntableB.Columns.Add(column); // column still in tableA\n// after\nif (column.Parent is Table t) { t.Columns.Remove(column); }\ntableB.Columns.Add(column);","handlingStrategy":"validation","validationCode":"if (col.Parent != null && col.Parent is not DummyProxy) { /* remove from existing parent first */ }","typeGuard":"bool IsUnparented(TableColumn col) => col.Parent == null || col.Parent is DummyProxy;","tryCatchPattern":"try { table.Columns.Add(col); } catch (ArgumentException) { DetachColumn(col); table.Columns.Add(col); }","preventionTips":["Ensure each TableColumn belongs to exactly one table","Detach logical children before re-adding a column to a different table"],"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"}