{"record":{"id":"eb6852a7ab8bc993","repo":"dotnet/wpf","slug":"sr-flowdocumentscrollviewercanhaveonlyonechild","errorCode":null,"errorMessage":"SR.FlowDocumentScrollViewerCanHaveOnlyOneChild","messagePattern":"SR\\.FlowDocumentScrollViewerCanHaveOnlyOneChild","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs","lineNumber":1800,"sourceCode":"        //\n        //  IAddChild Members\n        //\n        //-------------------------------------------------------------------\n\n        #region IAddChild Members\n\n        /// <summary>\n        /// Called to add the object as a Child.\n        /// </summary>\n        /// <param name=\"value\">Object to add as a child.</param>\n        /// <remarks>FlowDocumentScrollViewer only supports a single child of type IDocumentPaginator.</remarks>\n        void IAddChild.AddChild(Object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n            // Check if Content has already been set.\n            if (this.Document != null)\n            {\n                throw new ArgumentException(SR.FlowDocumentScrollViewerCanHaveOnlyOneChild);\n            }\n            if (!(value is FlowDocument))\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(FlowDocument)), nameof(value));\n            }\n            Document = value as FlowDocument;\n        }\n\n        /// <summary>\n        /// Called when text appears under the tag in markup\n        /// </summary>\n        /// <param name=\"text\">Text to add to the Object.</param>\n        /// <remarks>FlowDocumentScrollViewer does not support Text children.</remarks>\n        void IAddChild.AddText(string text)\n        {\n            XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);\n        }\n","sourceCodeStart":1782,"sourceCodeEnd":1818,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs#L1782-L1818","documentation":"FlowDocumentScrollViewer's explicit IAddChild.AddChild implementation throws this ArgumentException when a child is added while Document has already been set. The viewer accepts exactly one child, a FlowDocument, which becomes its Document.","triggerScenarios":"Adding a second child (XAML element inside <FlowDocumentScrollViewer> or a programmatic AddChild call) when Document is already assigned.","commonSituations":"Two children declared inside the viewer tag in XAML; re-adding a document instead of reassigning the Document property; leftover elements inside the viewer.","solutions":["Declare only a single FlowDocument child inside FlowDocumentScrollViewer in XAML.","Assign viewer.Document = newDocument to replace content instead of calling AddChild again.","Remove any non-FlowDocument or extra elements from inside the viewer tag."],"exampleFix":"// before (XAML)\n<FlowDocumentScrollViewer>\n  <FlowDocument/><FlowDocument/> <!-- throws -->\n</FlowDocumentScrollViewer>\n\n// after\n<FlowDocumentScrollViewer>\n  <FlowDocument/>\n</FlowDocumentScrollViewer>","handlingStrategy":"validation","validationCode":"if (viewer.Document != null)\n{\n    viewer.Document = newDoc; // replace, do not add\n}","typeGuard":"static bool CanAddChild(FlowDocumentScrollViewer v, object child) => v.Document == null && child is FlowDocument;","tryCatchPattern":"try { viewer.AddChild(value); }\ncatch (ArgumentException) { viewer.Document = value as FlowDocument; }","preventionTips":["Assign viewer.Document instead of calling AddChild when replacing content.","Keep exactly one FlowDocument child inside FlowDocumentScrollViewer in XAML."],"tags":["wpf","flowdocumentscrollviewer","xaml","invalid-argument-value"],"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"}