{"record":{"id":"b79617ac34c0228c","repo":"dotnet/wpf","slug":"sr-format-sr-textschema-childtypeisinvalid-this-gettype-name","errorCode":null,"errorMessage":"SR.Format(SR.TextSchema_ChildTypeIsInvalid, this.GetType().Name, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.TextSchema_ChildTypeIsInvalid, this\\.GetType\\(\\)\\.Name, value\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs","lineNumber":836,"sourceCode":"                            if (blockContainer.Child != null)\n                            {\n                                throw new ArgumentException(SR.Format(SR.TextSchema_ThisBlockUIContainerHasAChildUIElementAlready, this.GetType().Name, ((BlockUIContainer)this).Child.GetType().Name, value.GetType().Name));\n                            }\n\n                            blockContainer.Child = uie;\n                        }\n                        else\n                        {\n                            if (TextSchema.IsValidChild(/*parent:*/this, /*childType:*/typeof(InlineUIContainer)))\n                            {\n                                // Create implicit InlineUIContainer wrapper for this UIElement\n                                InlineUIContainer implicitInlineUIContainer = Inline.CreateImplicitInlineUIContainer(this);\n                                Append(implicitInlineUIContainer);\n                                implicitInlineUIContainer.Child = uie;\n                            }\n                            else\n                            {\n                                throw new ArgumentException(SR.Format(SR.TextSchema_ChildTypeIsInvalid, this.GetType().Name, value.GetType().Name));\n                            }\n                        }\n                    }\n                }\n                else\n                {\n                    throw new ArgumentException(SR.Format(SR.TextSchema_ChildTypeIsInvalid, this.GetType().Name, value.GetType().Name));\n                }\n            }\n        }\n\n        ///<summary>\n        /// Called when text appears under the tag in markup\n        ///</summary>\n        ///<param name=\"text\">\n        /// Text to Add to this TextElement\n        ///</param>\n        /// <ExternalAPI/>","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs#L818-L854","documentation":"TextElement.AddChild throws ArgumentException when the text schema does not allow a UIElement child of the given type in this element. For inline contexts where an implicit InlineUIContainer cannot be created (or the parent type disallows it), the child type is rejected with TextSchema_ChildTypeIsInvalid naming this element type and the value type.","triggerScenarios":"Calling AddChild with a UIElement whose type is not permitted as a child of this TextElement per the text schema (e.g. a block-level UIElement into a Run/Paragraph inline position that can't host it).","commonSituations":"Programmatic FlowDocument construction placing UIElements in schema-invalid positions; XAML where a UIElement child is nested under an element that can't contain it.","solutions":["Place the UIElement in a schema-valid parent (e.g. InlineUIContainer for inline, BlockUIContainer for block).","Verify the allowed child types of the target element before AddChild.","Convert the child to a supported wrapper type explicitly."],"exampleFix":"// before\nrun.AddChild(myGrid); // invalid child type for Run\n// after\nvar container = new InlineUIContainer(myGrid);\nparagraph.Inlines.Add(container);","handlingStrategy":"validation","validationCode":"bool isValidChild = element is Paragraph || element is Span; // verify schema allows UIElement child here\nif (!isValidChild) throw new InvalidOperationException(\"Place UIElement in InlineUIContainer\");","typeGuard":null,"tryCatchPattern":"try { element.AddChild(uie); }\ncatch (ArgumentException) { var c = new InlineUIContainer(uie); ((Paragraph)element).Inlines.Add(c); }","preventionTips":["Consult the text schema for allowed child types","Wrap UIElements in InlineUIContainer/BlockUIContainer explicitly","Validate hierarchy when generating FlowDocuments programmatically"],"tags":["wpf","schema","argument"],"backgroundTag":"schema-validation-failed","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"}