{"record":{"id":"0d3c5b2e243bb998","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-0d3c5b","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PageContent))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(PageContent\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs","lineNumber":136,"sourceCode":"        /// Called to Add the object as a Child.\n        ///</summary>\n        /// <exception cref=\"ArgumentNullException\">value is NULL.</exception>\n        /// <exception cref=\"ArgumentException\">value is not of type PageContent.</exception>\n        /// <exception cref=\"InvalidOperationException\">A PageContent cannot be added while previous partial page isn't completely Loaded.</exception>\n        ///<param name=\"value\">\n        /// Object to add as a child\n        ///</param>\n        void IAddChild.AddChild(Object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n//             Dispatcher.VerifyAccess();\n\n            PageContent fp = value as PageContent;\n\n            if (fp == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PageContent)), nameof(value));\n            }\n\n            if (fp.IsInitialized)\n            {\n                _pages.Add(fp);\n            }\n            else\n            {\n                DocumentsTrace.FixedFormat.FixedDocument.Trace($\"Page {_pages.Count} Deferred\");\n                if (_partialPage == null)\n                {\n                    _partialPage = fp;\n                    _partialPage.ChangeLogicalParent(this);\n                    _partialPage.Initialized += new EventHandler(OnPageLoaded);\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.PrevoiusPartialPageContentOutstanding);","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs#L118-L154","documentation":"This ArgumentException is thrown by FixedDocument.IAddChild.AddChild when the value is not a PageContent. FixedDocument pages are represented solely by PageContent objects, so any other child type is rejected.","triggerScenarios":"Adding a child to FixedDocument via IAddChild (or XAML) that is not a PageContent — e.g. adding a FixedPage directly, or a UIElement.","commonSituations":"XAML that nests <FixedPage> directly under <FixedDocument> instead of wrapping it in <PageContent>; programmatic document construction with wrong child type.","solutions":["Wrap content in a PageContent element and add that to the document","Use Pages.Add(pageContent) with a properly initialized PageContent","In XAML use <PageContent><FixedPage>...</FixedPage></PageContent>","Check the offending type in the message"],"exampleFix":"// before\nfixedDocument.AddChild(new FixedPage());\n// after\nvar pc = new PageContent();\n((IAddChild)pc).AddChild(new FixedPage());\nfixedDocument.Pages.Add(pc);","handlingStrategy":"type-guard","validationCode":"if (value is not PageContent pc) throw new ArgumentException(\"FixedDocument children must be PageContent\");","typeGuard":"bool IsPageContent(object o) => o is PageContent;","tryCatchPattern":"try { ((IAddChild)fixedDocument).AddChild(value); } catch (ArgumentException ex) { /* wrap value in PageContent and retry */ }","preventionTips":["Always wrap FixedPage in PageContent","Use fixedDocument.Pages.Add instead of IAddChild","In XAML keep <PageContent> between FixedDocument and FixedPage"],"tags":["wpf","argumentexception","xps-fixeddocument","type-mismatch"],"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"}