{"record":{"id":"fe473b0e3c95cef3","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-fe473b","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(StoryFragment))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(StoryFragment\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/StoryFragments.cs","lineNumber":46,"sourceCode":"        public void Add(StoryFragment storyFragment)\n        {\n            ArgumentNullException.ThrowIfNull(storyFragment);\n\n            ((IAddChild) this).AddChild(storyFragment);\n        }\n\n        void IAddChild.AddChild(object value)\n        {\n            //\n            // Only the StoryFragment type are accepted. \n            //\n            if (value is StoryFragment)\n            {\n                _elementList.Add( (StoryFragment) value);\n                return;\n            }\n\n            throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(StoryFragment)), nameof(value));\n        }\n        \n        void IAddChild.AddText(string text) { } \n        \n        IEnumerator<StoryFragment> IEnumerable<StoryFragment>.GetEnumerator()\n        {\n            throw new NotSupportedException();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<StoryFragment>)this).GetEnumerator();\n        }\n        \n        internal List<StoryFragment> StoryFragmentList\n        {\n            get\n            {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/StoryFragments.cs#L28-L64","documentation":"This ArgumentException is thrown by StoryFragments.AddChild when the child passed is not a StoryFragment. StoryFragments is the root of the XPS story structure and only accepts StoryFragment children.","triggerScenarios":"Calling AddChild on a StoryFragments instance with any object other than StoryFragment — e.g. adding SectionStructure or ParagraphStructure at the root level.","commonSituations":"Misreading the story hierarchy and adding block elements directly to the StoryFragments root; XAML with a structure element as a direct child of StoryFragments.","solutions":["Create a StoryFragment, add block elements to it, then add the fragment to StoryFragments","Keep SectionStructure/ParagraphStructure/etc. inside StoryFragment, not StoryFragments","Verify the child's runtime type from the message","Type-check with 'is StoryFragment' before adding"],"exampleFix":"// before\nstoryFragments.AddChild(new SectionStructure());\n// after\nvar fragment = new StoryFragment();\nfragment.BlockElements.Add(new SectionStructure());\nstoryFragments.AddChild(fragment);","handlingStrategy":"type-guard","validationCode":"if (value is not StoryFragment) throw new ArgumentException(\"StoryFragments.AddChild only accepts StoryFragment\");","typeGuard":"bool IsFragment(object o) => o is StoryFragment;","tryCatchPattern":"try { fragments.AddChild(value); } catch (ArgumentException ex) { /* log and wrap in a fragment instead */ }","preventionTips":["Always create a StoryFragment wrapper for story content","Keep block elements at fragment level","Use StoryFragments.Fragments typed collection"],"tags":["wpf","argumentexception","xps-story-structure","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"}