dotnet/wpf · error · ArgumentException
SR.TableCollectionInOtherCollection
Error message
SR.TableCollectionInOtherCollection
What it means
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.
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
Example fix
// before
tableB.Columns.Add(column); // column still in tableA
// after
if (column.Parent is Table t) { t.Columns.Remove(column); }
tableB.Columns.Add(column); Defensive patterns
Strategy: validation
Validate before calling
if (col.Parent != null && col.Parent is not DummyProxy) { /* remove from existing parent first */ } Type guard
bool IsUnparented(TableColumn col) => col.Parent == null || col.Parent is DummyProxy;
Try / catch
try { table.Columns.Add(col); } catch (ArgumentException) { DetachColumn(col); table.Columns.Add(col); } Prevention
- Ensure each TableColumn belongs to exactly one table
- Detach logical children before re-adding a column to a different table
When it happens
Trigger: 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.
Common situations: Reusing a single TableColumn instance across two tables; moving columns between tables without removal; binding the same column collection instance to multiple tables.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- SR.TableCollectionWrongProxyParent
- SR.TableCollectionOutOfRange
- " }} " element found. Expected fixed page element ( }} ).
- ' ' ContentType is not valid.
- ' ' ID is not a valid XSD ID.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/97c616173a2589b5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs:150
internal override void PrivateConnectChild(int index, TableColumn item)
{
Debug.Assert(item != null && item.Index == -1);
Debug.Assert(Items[index] == null);
// If the TItem is already parented correctly through a proxy, there's no need
// to change parentage. Otherwise, it should be parented to Owner.
if (item.Parent is DummyProxy)
{
if (LogicalTreeHelper.GetParent(item.Parent) != Owner)
{
throw new System.ArgumentException(SR.TableCollectionWrongProxyParent);
}
}
else
{
if (item.Parent != null)
{
throw new System.ArgumentException(SR.TableCollectionInOtherCollection);
}
Owner.AddLogicalChild(item);
}
// add the item into collection's array
Items[index] = item;
item.Index = index;
// notify the TItem about the change
item.OnEnterParentTree();
}
/// <summary>
/// Notifies the TItem about the event;
/// Disconnects the item from the model tree;
/// Sets the TItem's slot in the collection's array to null.
/// </summary>View on GitHub (pinned to 81131a70a4)