dotnet/wpf · error · ArgumentException

SR.ReachSerialization_ExpectedFixedDocument

Error message

SR.ReachSerialization_ExpectedFixedDocument

What it means

NgcSerializer.SerializeObject (the FixedDocument overload) casts the serializedObject to FixedDocument and, when the cast yields null, throws ArgumentException(SR.ReachSerialization_ExpectedFixedDocument). This serializer entry point is typed for FixedDocument only.

Solutions

  1. Pass a FixedDocument instance to this SerializeObject overload.
  2. Use the FixedDocumentSequence serializer for sequences and the FixedPage serializer for pages.
  3. Add an 'is FixedDocument' guard at the call site to fail with a clearer message.

Example fix

// before
fixedDocSerializer.SerializeObject(page); // page is FixedPage
// after
if (page is FixedDocument doc) fixedDocSerializer.SerializeObject(doc);
else pageSerializer.SerializeObject(page);
Defensive patterns

Strategy: type-guard

Validate before calling

if (obj is not FixedDocument)
    throw new ArgumentException("FixedDocument serializer requires a FixedDocument instance");

Type guard

bool IsFixedDocument(object o) => o is FixedDocument;

Try / catch

try { serializer.SerializeObject(obj); }
catch (ArgumentException ex) when (ex.Message.Contains("FixedDocument")) { /* route to the correct serializer for obj's actual type */ }

Prevention

When it happens

Trigger: Calling this SerializeObject overload with anything other than a FixedDocument instance (null is separately guarded) — e.g. a FixedPage, FixedDocumentSequence, or custom type.

Common situations: Invoking the wrong NgcSerializer for the document level (using the FixedDocument serializer for a sequence or a page); callers binding object variables typed as object.

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/6058955471a50a43. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs:87

            ArgumentNullException.ThrowIfNull(manager);
        }

        /// <summary>
        ///
        /// </summary>
        public
        override
        void
        SerializeObject(
            Object serializedObject
            )
        {
            ArgumentNullException.ThrowIfNull(serializedObject);
            FixedDocument fd = serializedObject as FixedDocument;
            if( fd == null )
            {

               throw new ArgumentException(SR.ReachSerialization_ExpectedFixedDocument);
            }
            NgcSerializationManager ngcManager = SerializationManager as NgcSerializationManager;

            ngcManager.StartDocument(fd,true);

            ReachSerializer serializer = ngcManager.GetSerializer(fd.Pages);
            serializer.SerializeObject(fd.Pages);

            ngcManager.EndDocument();
        }


        /// <summary>
        /// The method is called once the object data is discovered at that
        /// point of the serialization process.
        /// </summary>
        /// <param name="serializableObjectContext">
        /// The context of the object to be serialized at this time.

View on GitHub (pinned to 81131a70a4)