{"record":{"id":"3219c67d07660d6e","repo":"dotnet/wpf","slug":"sr-format-sr-textschema-3219c6","errorCode":null,"errorMessage":"SR.Format(SR.TextSchema_ThisBlockUIContainerHasAChildUIElementAlready, this.GetType().Name, ((BlockUIContainer)this).Child.GetType().Name, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.TextSchema_ThisBlockUIContainerHasAChildUIElementAlready, this\\.GetType\\(\\)\\.Name, \\(\\(BlockUIContainer\\)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":820,"sourceCode":"                {\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                        {\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                        }","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextElement.cs#L802-L838","documentation":"TextElement.AddChild for a BlockUIContainer throws ArgumentException when the block container already holds a Child UIElement. BlockUIContainer permits exactly one child, mirroring InlineUIContainer; the error names the container type, current child type, and attempted value type.","triggerScenarios":"Calling AddChild on a BlockUIContainer that already has a Child, e.g. adding a second UIElement (video, chart) to the same block container in a FlowDocument.","commonSituations":"Repopulating a FlowDocument at runtime without clearing containers; data binding assigning new content to an existing container.","solutions":["Clear blockContainer.Child before adding a new one.","Use a fresh BlockUIContainer for each new UIElement.","Check Child for null before calling AddChild."],"exampleFix":"// before\nblockContainer.AddChild(newGrid); // Child already set\n// after\nif (blockContainer.Child != null) blockContainer.Child = null;\nblockContainer.AddChild(newGrid);","handlingStrategy":"validation","validationCode":"bool canAdd = !(element is BlockUIContainer bc) || bc.Child == null;\nif (!canAdd) blockContainer.Child = null;","typeGuard":null,"tryCatchPattern":"try { blockContainer.AddChild(uie); }\ncatch (ArgumentException) { blockContainer.Child = null; blockContainer.AddChild(uie); }","preventionTips":["Check BlockUIContainer.Child before AddChild","Reset containers when rebuilding FlowDocument content","Create a new BlockUIContainer per UIElement"],"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-21T21:30:21.729Z"}