{"record":{"id":"418255669dadd1fc","repo":"dotnet/wpf","slug":"sr-format-sr-documentstructureunexpectedparametertype4-value","errorCode":null,"errorMessage":"SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(), typeof(ParagraphStructure), typeof(FigureStructure), typeof(ListStructure), typeof(TableStructure))","messagePattern":"SR\\.Format\\(SR\\.DocumentStructureUnexpectedParameterType4, value\\.GetType\\(\\), typeof\\(ParagraphStructure\\), typeof\\(FigureStructure\\), typeof\\(ListStructure\\), typeof\\(TableStructure\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":69,"sourceCode":"            _elementType = FixedElement.ElementType.Section;\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 FigureStructure\n                || value is ListStructure || value is TableStructure )\n            {\n                _elementList.Add((BlockElement)value);\n                return;\n            }\n\n            throw new ArgumentException(SR.Format(SR.DocumentStructureUnexpectedParameterType4, value.GetType(),\n                typeof(ParagraphStructure), typeof(FigureStructure), typeof(ListStructure), typeof(TableStructure)), \n                nameof(value));\n        }\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\n    /// <summary>","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L51-L87","documentation":"StoryFragment/SectionStructure AddChild (SemanticBasicElement) only accepts document-structure block elements: ParagraphStructure, FigureStructure, ListStructure or TableStructure. Any other object passed to IAddChild.AddChild is rejected with ArgumentException describing the value's actual type and the four allowed types.","triggerScenarios":"Calling AddChild with a non-BlockElement such as NamedElement, a UIElement, or a string on a container expecting structural blocks (e.g. adding a NamedElement directly to a SectionStructure instead of wrapping it in a ParagraphStructure).","commonSituations":"XAML parsing of fixed-document structure where a wrong child element appears under a section; programmatic construction of a FixedDocument structure mixing NamedElement leaves into block containers.","solutions":["Wrap the named run in a ParagraphStructure > NamedElement hierarchy before adding.","Only add ParagraphStructure, FigureStructure, ListStructure, or TableStructure to this container.","Use the strongly typed Add(NamedElement) method on the container that expects leaves."],"exampleFix":"// before\nsection.AddChild(namedElement);\n// after\nvar para = new ParagraphStructure();\npara.AddChild(namedElement);\nsection.AddChild(para);","handlingStrategy":"type-guard","validationCode":"if (value is not (ParagraphStructure or FigureStructure or ListStructure or TableStructure)) throw new ArgumentException($\"{value.GetType()} is not a valid block structure child.\");","typeGuard":"bool IsValidBlockChild(object v) => v is ParagraphStructure or FigureStructure or ListStructure or TableStructure;","tryCatchPattern":"try { section.AddChild(value); } catch (ArgumentException) { /* wrap value in ParagraphStructure or reject the input */ }","preventionTips":["Remember the schema: sections take only the four block structures.","Wrap named runs in ParagraphStructure before adding.","Prefer the strongly typed Add/typed collections over IAddChild in code."],"tags":["wpf","document-structures","argument-validation"],"backgroundTag":"type-mismatch","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"}