{"record":{"id":"8a0fd1a8487d6870","repo":"dotnet/wpf","slug":"sr-format-sr-documentstructureunexpectedparametertype4-value-8a0fd1","errorCode":null,"errorMessage":"SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(), typeof(ParagraphStructure), typeof(TableStructure), typeof(ListStructure), typeof(FigureStructure))","messagePattern":"SR\\.Format\\(SR\\.DocumentStructureUnexpectedParameterType4, value\\.GetType\\(\\), typeof\\(ParagraphStructure\\), typeof\\(TableStructure\\), typeof\\(ListStructure\\), typeof\\(FigureStructure\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":243,"sourceCode":"        {\n            _elementType = FixedElement.ElementType.ListItem;\n        }\n\n        public void Add(BlockElement element)\n        {\n            ArgumentNullException.ThrowIfNull(element);\n            ((IAddChild) this).AddChild(element);\n        }\n\n        void IAddChild.AddChild(object value)\n        {\n            if (value is ParagraphStructure || value is TableStructure || value is ListStructure || value is FigureStructure)\n            {\n                _elementList.Add((BlockElement)value);\n                return;\n            }\n\n            throw new ArgumentException(SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(),\n                typeof(ParagraphStructure), typeof(TableStructure), typeof(ListStructure), typeof(FigureStructure)), nameof(value));\n        }\n        void IAddChild.AddText(string text) { }\n\n        IEnumerator<BlockElement> IEnumerable<BlockElement>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<BlockElement>)this).GetEnumerator();\n        }\n        \n        /// <summary>\n        ///\n        /// </summary>\n        public String Marker","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L225-L261","documentation":"This ArgumentException is thrown by FixedPageStructure.AddChild (via IAddChild) when a child object added is not one of the four accepted block structure types: ParagraphStructure, TableStructure, ListStructure, or FigureStructure. WPF document structure containers only accept specific strongly-typed children so the XPS document structure remains valid.","triggerScenarios":"Calling IAddChild.AddChild on a FixedPageStructure (or via XAML parsing) with any object other than ParagraphStructure/TableStructure/ListStructure/FigureStructure, e.g. adding a TableRowStructure or a plain UIElement directly.","commonSituations":"Hand-building XPS document structure trees in code; XAML that nests a wrong element inside FixedPageStructure; porting code that assumed arbitrary children were accepted.","solutions":["Pass only ParagraphStructure, TableStructure, ListStructure or FigureStructure instances to AddChild","Wrap content in the correct container (e.g. put rows in TableStructure > TableRowGroupStructure > TableRowStructure)","Check that the element resolved in XAML is the intended structure type, not a same-named different class","Catch ArgumentException around AddChild to surface a clearer message"],"exampleFix":"// before\nfixedPageStructure.AddChild(new TableRowStructure());\n// after\nvar table = new TableStructure();\ntable.RowGroups.Add(new TableRowGroupStructure { rows = new TableRowStructure() });\nfixedPageStructure.AddChild(table);","handlingStrategy":"type-guard","validationCode":"if (!(value is ParagraphStructure || value is TableStructure || value is ListStructure || value is FigureStructure)) throw new ArgumentException($\"{value.GetType()} is not an accepted block structure type\");","typeGuard":"bool IsBlockStructure(object o) => o is ParagraphStructure || o is TableStructure || o is ListStructure || o is FigureStructure;","tryCatchPattern":"try { addChild(value); } catch (ArgumentException ex) { /* log ex.Message with value.GetType() */ }","preventionTips":["Only add the four accepted structure types to block containers","Nest rows/cells inside TableStructure properly","Prefer typed collection properties (e.g. Blocks) over IAddChild when possible"],"tags":["wpf","argumentexception","xps-document-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"}