{"record":{"id":"93410b973efb8de1","repo":"dotnet/wpf","slug":"sr-format-sr-documentstructureunexpectedparametertype1-value","errorCode":null,"errorMessage":"SR.Format(SR.DocumentStructureUnexpectedParameterType1, value.GetType(), typeof(NamedElement))","messagePattern":"SR\\.Format\\(SR\\.DocumentStructureUnexpectedParameterType1, value\\.GetType\\(\\), typeof\\(NamedElement\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":114,"sourceCode":"        {\n            _elementType = FixedElement.ElementType.Paragraph;\n        }\n\n        public void Add(NamedElement element)\n        {\n            ArgumentNullException.ThrowIfNull(element);\n            ((IAddChild) this).AddChild(element);\n        }\n        \n        void IAddChild.AddChild(object value)\n        {\n            if (value is NamedElement)\n            {\n                _elementList.Add((BlockElement)value);\n                return;\n            }\n\n            throw new ArgumentException(SR.Format(SR.DocumentStructureUnexpectedParameterType1, value.GetType(),\n                typeof(NamedElement)),\n                nameof(value));\n        }\n        \n        void IAddChild.AddText(string text) { }\n\n        IEnumerator<NamedElement> IEnumerable<NamedElement>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<NamedElement>)this).GetEnumerator();\n        }\n    }\n\n    /// <summary>","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L96-L132","documentation":"This AddChild overload (on ParagraphStructure-style containers) accepts only NamedElement children; anything else triggers ArgumentException with DocumentStructureUnexpectedParameterType1, reporting the value's actual type and the single accepted type NamedElement. It enforces the fixed schema of WPF document structures.","triggerScenarios":"Passing a ParagraphStructure, TableStructure, raw string or arbitrary object to IAddChild.AddChild on a container whose legal child is only NamedElement.","commonSituations":"XAML in fixed documents where a <ParagraphStructure> is nested where only a <NamedElement> (e.g. <x:P> run mapping) is allowed; hand-built document trees copying the wrong nesting pattern.","solutions":["Only add NamedElement instances (e.g. named runs) to this container.","Move structural elements (Paragraph/List/Table) to the parent SectionStructure instead.","Use IAddChild.AddText for plain text if the target supports it."],"exampleFix":"// before\nparagraphStructure.AddChild(new FigureStructure());\n// after\nparagraphStructure.AddChild(new NamedElement(\"x:P\"));","handlingStrategy":"type-guard","validationCode":"if (value is not NamedElement) throw new ArgumentException($\"{value.GetType()} is not a NamedElement.\");","typeGuard":"bool IsNamedElement(object v) => v is NamedElement;","tryCatchPattern":"try { container.AddChild(value); } catch (ArgumentException) { /* route non-NamedElement to the proper parent container */ }","preventionTips":["Only place NamedElement at leaf level of document structures.","Check the XSD of fixed document structure when hand-building XAML.","Use the typed Add(NamedElement) method instead of IAddChild."],"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"}