{"record":{"id":"25b4aafb72b43e78","repo":"dotnet/wpf","slug":"sr-format-sr-tableinvalidparentnodetype-newparent-gettype-25b4aa","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/TableRow.cs","lineNumber":89,"sourceCode":"        void IAddChild.AddText(string text)\n        {\n            XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);\n        }\n\n\n        /// <summary>\n        /// Called when tablerow gets new parent\n        /// </summary>\n        /// <param name=\"newParent\">\n        /// New parent of cell\n        /// </param>\n        internal override void OnNewParent(DependencyObject newParent)\n        {\n            DependencyObject oldParent = this.Parent;\n\n            if (newParent != null && !(newParent is TableRowGroup))\n            {\n                throw new InvalidOperationException(SR.Format(SR.TableInvalidParentNodeType, newParent.GetType().ToString()));\n            }\n\n            if (oldParent != null)\n            {\n                ((TableRowGroup)oldParent).Rows.InternalRemove(this);\n            }\n\n            base.OnNewParent(newParent);\n\n            if (newParent != null)\n            {\n                ((TableRowGroup)newParent).Rows.InternalAdd(this);\n            }\n        }\n\n        #endregion Public Methods\n\n        //------------------------------------------------------","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TableRow.cs#L71-L107","documentation":"TableRow.OnNewParent validates that a row's new parent is a TableRowGroup (or null). Assigning a TableRow to any other DependencyObject throws InvalidOperationException naming the offending type, since TableRow may only be parented by a TableRowGroup.","triggerScenarios":"Reparenting a TableRow into a Table, TableCell, or arbitrary DependencyObject; adding a row to a collection other than TableRowGroup.Rows.","commonSituations":"Programmatic table construction with wrong nesting order; XAML placing TableRow directly under Table; refactor that swapped TableRowGroup for Table.","solutions":["Add the TableRow to a TableRowGroup's Rows collection","Fix XAML nesting: Table > TableRowGroup > TableRow > TableCell","Guard reparenting code with 'newParent is TableRowGroup' before assignment"],"exampleFix":"// before\ntable.Rows.Add(row); // Table has RowGroups, not Rows\n// after\nvar group = new TableRowGroup();\ngroup.Rows.Add(row);\ntable.RowGroups.Add(group);","handlingStrategy":"validation","validationCode":"bool ok = newParent == null || newParent is TableRowGroup;","typeGuard":"static bool CanParentRow(DependencyObject p) => p is TableRowGroup || p == null;","tryCatchPattern":"try { group.Rows.Add(row); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"parent\")) { /* fix nesting */ }","preventionTips":["Add rows only to TableRowGroup.Rows","Keep XAML nesting Table > TableRowGroup > TableRow","Check parent type before manual 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-22T01:17:13.364Z"}