{"record":{"id":"9643ee41ea63f621","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-9643ee","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableCellStructure))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(TableCellStructure\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":381,"sourceCode":"        public TableRowStructure()\n        {\n            _elementType = FixedElement.ElementType.TableRow;\n        }\n\n        public void Add(TableCellStructure tableCell)\n        {\n            ArgumentNullException.ThrowIfNull(tableCell);\n            ((IAddChild) this).AddChild(tableCell);\n        }\n    \n        void IAddChild.AddChild(object value)\n        {\n            if (value is TableCellStructure)\n            {\n                _elementList.Add((TableCellStructure)value);\n                return;\n            }\n            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(TableCellStructure)), nameof(value));\n        }\n        \n        void IAddChild.AddText(string text) { }\n        \n        IEnumerator<TableCellStructure> IEnumerable<TableCellStructure>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<TableCellStructure>)this).GetEnumerator();\n        }\n    }\n\n    /// <summary>\n    ///\n    /// </summary>","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L363-L399","documentation":"This ArgumentException is thrown by TableCellStructure.AddChild when the child object is not a TableCellStructure-accepted block element. Cells only accept block-level structure children (ParagraphStructure, TableStructure, ListStructure, FigureStructure) per the XPS schema implemented by this container's twin (see index 2664 pattern in the same file).","triggerScenarios":"Calling AddChild on TableCellStructure with an object that fails the accepted-type test — e.g. a Run, a TextBlock, or a TableRowStructure.","commonSituations":"Putting inline flow content directly into cells; converting FixedDocument flow code to document-structure code without wrapping content.","solutions":["Add only ParagraphStructure/TableStructure/ListStructure/FigureStructure instances to the cell","Wrap inline content in a ParagraphStructure before adding","Check the actual runtime type in the exception message","Guard with a type check before AddChild"],"exampleFix":"// before\ncell.AddChild(\"some text\");\n// after\nvar para = new ParagraphStructure();\ncell.Blocks.Add(para);","handlingStrategy":"type-guard","validationCode":"if (value is not (ParagraphStructure or TableStructure or ListStructure or FigureStructure)) throw new ArgumentException(\"Cell does not accept this child type\");","typeGuard":"bool IsCellBlock(object o) => o is ParagraphStructure || o is TableStructure || o is ListStructure || o is FigureStructure;","tryCatchPattern":"try { cellAddChild(value); } catch (ArgumentException ex) { /* inspect ex.Message for the bad type */ }","preventionTips":["Wrap inline content in ParagraphStructure before adding to cells","Never add rows/row-groups to a cell","Prefer the typed Blocks collection"],"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"}