{"record":{"id":"34632316b9655bfc","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-346323","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableRowGroupStructure))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(TableRowGroupStructure\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":296,"sourceCode":"        public TableStructure()\n        {\n            _elementType = FixedElement.ElementType.Table;\n        }\n\n        public void Add(TableRowGroupStructure tableRowGroup)\n        {\n            ArgumentNullException.ThrowIfNull(tableRowGroup);\n            ((IAddChild) this).AddChild(tableRowGroup);\n        }\n        \n        void IAddChild.AddChild(object value)\n        {\n            if (value is TableRowGroupStructure)\n            {\n                _elementList.Add((TableRowGroupStructure)value);\n                return;\n            }\n            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableRowGroupStructure)), nameof(value));\n        }\n        \n        void IAddChild.AddText(string text) { }\n        \n        IEnumerator<TableRowGroupStructure> IEnumerable<TableRowGroupStructure>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<TableRowGroupStructure>)this).GetEnumerator();\n        }\n    }\n\n    /// <summary>\n    ///\n    /// </summary>","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L278-L314","documentation":"This ArgumentException is thrown by TableRowGroupStructure.AddChild when the supplied child is not a TableRowGroupStructure. The container only accepts row groups as children, keeping the XPS table structure hierarchy (TableStructure -> TableRowGroupStructure) valid.","triggerScenarios":"Calling AddChild on TableRowGroupStructure with an object that is not TableRowGroupStructure, e.g. adding a TableRowStructure directly or a ParagraphStructure.","commonSituations":"Building XPS tables programmatically and skipping a hierarchy level; XAML where a row is placed directly in a table without a row group.","solutions":["Add only TableRowGroupStructure instances; nest TableRowStructure inside the row group","Match the XPS hierarchy: TableStructure contains TableRowGroupStructure contains TableRowStructure contains TableCellStructure","Inspect value.GetType() in the message to see what was actually passed","Guard the call with an 'is TableRowGroupStructure' check"],"exampleFix":"// before\nrowGroup.AddChild(new TableRowStructure());\n// after\nvar row = new TableRowStructure();\nrowGroup.Rows.Add(row); // via typed collection, or add rows through a group's own API","handlingStrategy":"type-guard","validationCode":"if (value is not TableRowGroupStructure) throw new ArgumentException(\"TableRowGroupStructure.AddChild only accepts TableRowGroupStructure\");","typeGuard":"bool IsRowGroup(object o) => o is TableRowGroupStructure;","tryCatchPattern":"try { rowGroupAddChild(value); } catch (ArgumentException ex) { /* surface ex.ParamName and message */ }","preventionTips":["Remember the hierarchy: group contains rows, rows contain cells","Build tables top-down: TableStructure -> TableRowGroupStructure -> TableRowStructure -> TableCellStructure","Use typed collections instead of IAddChild"],"tags":["wpf","argumentexception","xps-table-structure","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}