{"record":{"id":"8d15002408134d5f","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-8d1500","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(FixedPage))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(FixedPage\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs","lineNumber":171,"sourceCode":"        ///</summary>\n        /// <exception cref=\"ArgumentNullException\">value is NULL.</exception>\n        /// <exception cref=\"ArgumentException\">value is not of type FixedPage.</exception>\n        /// <exception cref=\"InvalidOperationException\">A child already exists (a PageContent can have at most one child).</exception>\n        ///<param name=\"value\">\n        /// Object to add as a child\n        ///</param>\n        /// <ExternalAPI/>\n        void IAddChild.AddChild(Object value)\n        {\n//             VerifyAccess();\n\n            ArgumentNullException.ThrowIfNull(value);\n\n\n            FixedPage fp = value as FixedPage;\n            if (fp == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(FixedPage)), nameof(value));\n            }\n\n            if (_child != null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.CanOnlyHaveOneChild, typeof(PageContent), value));\n            }\n\n            _pageRef = null;\n            _child   = fp;\n            LogicalTreeHelper.AddLogicalChild(this, _child);\n        }\n\n        ///<summary>\n        /// Called when text appears under the tag in markup\n        ///</summary>\n        ///<param name=\"text\">\n        /// Text to Add to the Object\n        ///</param>","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs#L153-L189","documentation":"PageContent.AddChild throws ArgumentException with SR.UnexpectedParameterType when the value passed is not a FixedPage. PageContent may only host a FixedPage child; any other object type is rejected before being attached.","triggerScenarios":"Calling AddChild(obj) (or the IAddChild implementation) on a PageContent with an object that is not a FixedPage, e.g. a Page, Canvas, or deserialized element of a different type.","commonSituations":"XPS document construction where the wrong element type is inserted as page content; programmatic XAML building that assumes PageContent accepts arbitrary Visuals.","solutions":["Pass a FixedPage instance as the child value","Wrap or convert the content into a FixedPage before adding","Fix XAML so only <FixedPage> appears inside <PageContent>"],"exampleFix":"// before\npageContent.AddChild(new Canvas());\n// after\nFixedPage fp = new FixedPage();\nfp.Children.Add(new Canvas());\npageContent.AddChild(fp);","handlingStrategy":"type-guard","validationCode":"if (value == null) throw new ArgumentNullException(nameof(value));\nif (value is not FixedPage) throw new ArgumentException(\"Expected FixedPage\", nameof(value));","typeGuard":"bool IsValidChild(object v) => v is FixedPage;","tryCatchPattern":"try { pageContent.AddChild(value); } catch (ArgumentException ex) { /* log expected-FixedPage violation */ }","preventionTips":["Only construct FixedPage instances as PageContent children","Validate element type before building XPS content trees","Prefer the strongly-typed Child property over IAddChild where possible"],"tags":["wpf","argument","type-mismatch","xps"],"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"}