dotnet/wpf · error · ArgumentException

SR.TableCollectionWrongProxyParent

Error message

SR.TableCollectionWrongProxyParent

What it means

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.

Solutions

  1. Remove the column from its current table's collection before adding it to another
  2. Create a new TableColumn instance for the second table instead of reusing one
  3. If the proxy parent is the correct table, ensure the collection's Owner matches (use the right table's collection)

Example fix

// before
otherTable.Columns.Add(sharedColumn);
// after
currentTable.Columns.Remove(sharedColumn);
otherTable.Columns.Add(sharedColumn);
Defensive patterns

Strategy: validation

Validate before calling

if (col.Parent != null && col.Parent is not DummyProxy) throw new InvalidOperationException("Column already parented.");

Try / catch

try { table.Columns.Add(col); } catch (ArgumentException) { previousTable.Columns.Remove(col); table.Columns.Add(col); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/703169f4c3c6c676. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TableColumnCollectionInternal.cs:143

        /// <exception cref="ArgumentException">
        /// If the new item has already a parent or if the slot at the specified index is not null.
        /// </exception>
        /// <remarks>
        /// Note that the function requires that _item[index] == null and
        /// it also requires that the passed in item is not included into another ContentElementCollection.
        /// </remarks>
        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();

View on GitHub (pinned to 81131a70a4)