dotnet/wpf · error · ArgumentException

SR.Format(SR.DocumentStructureUnexpectedParameterType6…

Error message

SR.Format(SR.DocumentStructureUnexpectedParameterType6, value.GetType(), typeof(SectionStructure), typeof(ParagraphStructure), typeof(FigureStructure), typeof(ListStructure), typeof(TableStructure), typeof(StoryBreak))

What it means

This ArgumentException is thrown by StoryFragment.AddChild when the child is not one of the six accepted block types: SectionStructure, ParagraphStructure, FigureStructure, ListStructure, TableStructure, or StoryBreak. StoryFragment enforces the XPS story structure schema at its content level.

Solutions

  1. Use only the six accepted types as StoryFragment children
  2. Move non-story elements (like PageContent) to FixedDocument instead
  3. Inspect value.GetType() in the message to identify the bad object
  4. Guard the call with an 'is' check against the accepted types

Example fix

// before
fragment.AddChild(new PageContent());
// after
fixedDocument.Pages.Add(new PageContent()); // page content goes in the document, not the story
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value is SectionStructure || value is ParagraphStructure || value is FigureStructure || value is ListStructure || value is TableStructure || value is StoryBreak)) throw new ArgumentException($"{value.GetType()} not a valid StoryFragment child");

Type guard

bool IsStoryBlock(object o) => o is SectionStructure || o is ParagraphStructure || o is FigureStructure || o is ListStructure || o is TableStructure || o is StoryBreak;

Try / catch

try { fragment.AddChild(value); } catch (ArgumentException ex) { /* redirect non-story types to their own containers */ }

Prevention

When it happens

Trigger: Calling AddChild on a StoryFragment with any other object — e.g. a PageContent, a TableRowStructure, or a plain UIElement.

Common situations: Mixing FixedPage content elements into StoryFragment content; hand-written XPS story markup with a wrong nested element.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/0bca10677576a713. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentStructures/StoryFragments.cs:106

            ArgumentNullException.ThrowIfNull(element);
            ((IAddChild) this).AddChild(element);
        }
        
        void IAddChild.AddChild(object value)
        {
            //
            // Only the following type are accepted. 
            // Section|Paragraph|Inline(Bold|Italic|Underline)|Floater|Figure|List
            // |Table|StoryBreak
            //
            if (value is SectionStructure || value is ParagraphStructure || value is FigureStructure 
                || value is ListStructure || value is TableStructure || value is StoryBreak)
            {
                _elementList.Add( (BlockElement) value);
                return;
            }

            throw new ArgumentException(SR.Format(SR.DocumentStructureUnexpectedParameterType6, value.GetType(),
                typeof(SectionStructure), typeof(ParagraphStructure), typeof(FigureStructure), typeof(ListStructure), typeof(TableStructure), typeof(StoryBreak)),
                nameof(value));
        }
        void IAddChild.AddText(string text) { }

        IEnumerator<BlockElement> IEnumerable<BlockElement>.GetEnumerator()
        {
            throw new NotSupportedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<BlockElement>)this).GetEnumerator();
        }

        /// <summary>
        /// The element name
        /// </summary>

View on GitHub (pinned to 81131a70a4)