{"record":{"id":"8141a9c6e4501a79","repo":"dotnet/wpf","slug":"sr-unexpectedparametertype-flowdocumentscrollviewer","errorCode":null,"errorMessage":"SR.UnexpectedParameterType","messagePattern":"SR\\.UnexpectedParameterType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs","lineNumber":1804,"sourceCode":"\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\n        #endregion IAddChild Members\n\n        //-------------------------------------------------------------------\n        //","sourceCodeStart":1786,"sourceCodeEnd":1822,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/FlowDocumentScrollViewer.cs#L1786-L1822","documentation":"FlowDocumentScrollViewer's IAddChild.AddChild throws this ArgumentException (formatted with SR.UnexpectedParameterType) when the supplied value is not a FlowDocument. The only permitted child is a FlowDocument; the message includes the provided and expected type names.","triggerScenarios":"Calling AddChild with a non-FlowDocument value, or placing an element other than FlowDocument directly inside <FlowDocumentScrollViewer> in XAML.","commonSituations":"Nesting Paragraph, Grid or other elements directly under the viewer instead of inside a FlowDocument; generating children programmatically with the wrong type.","solutions":["Wrap the content in a FlowDocument before adding it as the viewer's child.","Use a different container control if you need arbitrary UI children rather than flow content.","Type-check before adding: if (value is FlowDocument doc) viewer.Document = doc;"],"exampleFix":"// before\nviewer.AddChild(new Run(\"text\")); // throws\n\n// after\nviewer.AddChild(new FlowDocument(new Paragraph(new Run(\"text\"))));","handlingStrategy":"type-guard","validationCode":"if (value is not FlowDocument doc)\n    throw new ArgumentException($\"Expected FlowDocument, got {value?.GetType().Name}\");\nviewer.Document = doc;","typeGuard":"static bool IsFlowDocument(object v) => v is FlowDocument;","tryCatchPattern":"try { viewer.AddChild(value); }\ncatch (ArgumentException) { // wrap value in a FlowDocument and retry }","preventionTips":["Type-check `is FlowDocument` before adding children to FlowDocumentScrollViewer.","Do not place raw paragraphs or panels directly under the viewer in XAML."],"tags":["wpf","flowdocumentscrollviewer","type-mismatch","xaml"],"backgroundTag":"type-mismatch","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"}