{"record":{"id":"139d3ce0eda4c7d2","repo":"dotnet/wpf","slug":"sr-format-sr-textschema-textelement","errorCode":null,"errorMessage":"SR.Format(SR.TextSchema_ThisInlineUIContainerHasAChildUIElementAlready, this.GetType().Name, ((InlineUIContainer)this).Child.GetType().Name, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.TextSchema_ThisInlineUIContainerHasAChildUIElementAlready, this\\.GetType\\(\\)\\.Name, \\(\\(InlineUIContainer\\)this\\)\\.Child\\.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":808,"sourceCode":"\n            TextElement te = value as TextElement;\n\n            if (te != null)\n            {\n                TextSchema.ValidateChild(/*parent:*/this, /*child:*/te, true /* throwIfIllegalChild */, true /* throwIfIllegalHyperlinkDescendent */);\n                Append(te);\n            }\n            else\n            {\n                UIElement uie = value as UIElement;\n                if (uie != null)\n                {\n                    InlineUIContainer inlineContainer = this as InlineUIContainer;\n                    if (inlineContainer != null)\n                    {\n                        if (inlineContainer.Child != null)\n                        {\n                            throw new ArgumentException(SR.Format(SR.TextSchema_ThisInlineUIContainerHasAChildUIElementAlready, this.GetType().Name, ((InlineUIContainer)this).Child.GetType().Name, value.GetType().Name));\n                        }\n\n                        inlineContainer.Child = uie;\n                    }\n                    else\n                    {\n                        BlockUIContainer blockContainer = this as BlockUIContainer;\n                        if (blockContainer != null)\n                        {\n                            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                        {","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs#L790-L826","documentation":"TextElement.AddChild for an InlineUIContainer throws ArgumentException when the container already has a Child UIElement. The WPF text schema allows only one child element per InlineUIContainer, so a second AddChild is rejected, naming the container type, existing child type, and new value type.","triggerScenarios":"Calling AddChild on an InlineUIContainer (or text element that resolves to one) whose Child property is already set, e.g. adding a second Image/Button to the same inline container.","commonSituations":"XAML parsing or code that reuses a container across data-binding updates without clearing the previous child.","solutions":["Clear the existing child (inlineContainer.Child = null or RemoveChild) before AddChild.","Create a new InlineUIContainer for the new UIElement.","Check the Child property before calling AddChild."],"exampleFix":"// before\ninlineContainer.AddChild(newButton); // already has an Image child\n// after\nif (inlineContainer.Child != null) inlineContainer.Child = null;\ninlineContainer.AddChild(newButton);","handlingStrategy":"validation","validationCode":"bool canAdd = !(element is InlineUIContainer ic) || ic.Child == null;\nif (!canAdd) container.Child = null; // clear first","typeGuard":null,"tryCatchPattern":"try { container.AddChild(uie); }\ncatch (ArgumentException) { container.Child = null; container.AddChild(uie); }","preventionTips":["Check Child for null before AddChild","Clear old children during data-binding updates","Use fresh containers for new UIElements"],"tags":["wpf","uielement","argument"],"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-22T01:17:13.364Z"}