{"record":{"id":"18feb2c33bf77b99","repo":"dotnet/wpf","slug":"sr-format-sr-tableinvalidparentnodetype-newparent-gettype-18feb2","errorCode":null,"errorMessage":"SR.Format(SR.TableInvalidParentNodeType, newParent.GetType().ToString())","messagePattern":"SR\\.Format\\(SR\\.TableInvalidParentNodeType, newParent\\.GetType\\(\\)\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs","lineNumber":289,"sourceCode":"        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        #region Private Methods\n\n        /// <summary>\n        /// Called when body receives a new parent (via OM or text tree)\n        /// </summary>\n        /// <param name=\"newParent\">\n        /// New parent of body\n        /// </param>\n        internal override void OnNewParent(DependencyObject newParent)\n        {\n            DependencyObject oldParent = this.Parent;\n\n            if (newParent != null && !(newParent is Table))\n            {\n                throw new InvalidOperationException(SR.Format(SR.TableInvalidParentNodeType, newParent.GetType().ToString()));\n            }\n\n            if (oldParent != null)\n            {\n                OnExitParentTree();\n                ((Table)oldParent).RowGroups.InternalRemove(this);\n                OnAfterExitParentTree(oldParent as Table);\n            }\n\n            base.OnNewParent(newParent);\n\n            if (newParent != null)\n            {\n                ((Table)newParent).RowGroups.InternalAdd(this);\n                OnEnterParentTree();\n            }\n        }\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRowGroup.cs#L271-L307","documentation":"TableRowGroup.OnNewParent validates that a row group's new parent is a Table (or null). Reparenting a TableRowGroup to any other DependencyObject throws InvalidOperationException naming the actual type, because TableRowGroup may only be a direct child of a Table's RowGroups collection.","triggerScenarios":"Adding a TableRowGroup to a non-Table container (e.g. a Grid, StackPanel children, or another TableRowGroup) or direct reparenting APIs with a non-Table parent.","commonSituations":"Confusing Table with Grid nesting; moving row groups between documents/trees with incompatible parents; XAML with TableRowGroup outside Table.","solutions":["Add the TableRowGroup to a Table's RowGroups collection","Fix XAML so TableRowGroup is a direct child of Table","Check 'newParent is Table' before reparenting"],"exampleFix":"// before\nstackPanel.Children.Add(rowGroup); // invalid parent\n// after\nvar table = new Table();\ntable.RowGroups.Add(rowGroup);","handlingStrategy":"validation","validationCode":"bool ok = newParent == null || newParent is Table;","typeGuard":"static bool CanParentRowGroup(DependencyObject p) => p is Table || p == null;","tryCatchPattern":"try { table.RowGroups.Add(group); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"parent\")) { /* fix nesting */ }","preventionTips":["Add row groups only to Table.RowGroups","Do not confuse Table with Grid child collections","Validate container type before reparenting"],"tags":["wpf","table","xaml-nesting"],"backgroundTag":"invalid-parent-element","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"}