{"record":{"id":"4799f82b03316260","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-4799f8","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(ListItemStructure))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(ListItemStructure\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs","lineNumber":201,"sourceCode":"        {\n            _elementType = FixedElement.ElementType.List;\n        }\n\n        public void Add(ListItemStructure listItem)\n        {\n            ArgumentNullException.ThrowIfNull(listItem);\n            ((IAddChild) this).AddChild(listItem);\n        }\n        \n        void IAddChild.AddChild(object value)\n        {\n            if (value is ListItemStructure)\n            {\n                _elementList.Add((ListItemStructure)value);\n                return;\n            }\n\n            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(ListItemStructure)), nameof(value));\n        }\n        \n        void IAddChild.AddText(string text) { }\n\n        IEnumerator<ListItemStructure> IEnumerable<ListItemStructure>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<ListItemStructure>)this).GetEnumerator();\n        }\n    }\n    /// <summary>\n    ///\n    /// </summary>\n    public class ListItemStructure : SemanticBasicElement, IAddChild, IEnumerable<BlockElement>, IEnumerable","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/SemanticBasicElement.cs#L183-L219","documentation":"This AddChild implementation (ListItemStructure container) accepts only ListItemStructure children (nested list items) and throws ArgumentException with UnexpectedParameterType for any other value, echoing the value's type and the expected ListItemStructure type.","triggerScenarios":"Calling AddChild with a NamedElement or ParagraphStructure etc. on a ListItemStructure; nesting error while constructing ListStructure/ListItemStructure trees where a named element was placed at item level instead of paragraph level.","commonSituations":"XAML fixed-document structures with a <NamedElement> directly under <ListItemStructure> instead of under a child container; programmatic tree building that skipped one hierarchy level.","solutions":["Wrap NamedElement in the intermediate structure level before adding, or add it to the ListStructure level that accepts it.","Only add ListItemStructure instances for nested list items here.","Use the typed Add(ListItemStructure) method for compile-time checking."],"exampleFix":"// before\nlistItemStructure.AddChild(new NamedElement(\"x:P\"));\n// after\nvar nested = new ListItemStructure();\nlistStructure.AddChild(nested);\n// named elements belong via the structure level that accepts them","handlingStrategy":"type-guard","validationCode":"if (value is not ListItemStructure) throw new ArgumentException($\"Expected ListItemStructure, got {value.GetType()}.\");","typeGuard":"bool IsListItemStructure(object v) => v is ListItemStructure;","tryCatchPattern":"try { listItem.AddChild(value); } catch (ArgumentException) { /* place NamedElements at the correct structural level instead */ }","preventionTips":["Only nest ListItemStructure inside ListItemStructure for sub-lists.","NamedElements belong under paragraph-level containers, not directly under items.","Use the typed Add(ListItemStructure) method to catch errors at compile time."],"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-21T21:30:21.729Z"}