{"record":{"id":"6058955471a50a43","repo":"dotnet/wpf","slug":"sr-reachserialization-expectedfixeddocument","errorCode":null,"errorMessage":"SR.ReachSerialization_ExpectedFixedDocument","messagePattern":"SR\\.ReachSerialization_ExpectedFixedDocument","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs","lineNumber":87,"sourceCode":"            ArgumentNullException.ThrowIfNull(manager);\n        }\n\n        /// <summary>\n        ///\n        /// </summary>\n        public\n        override\n        void\n        SerializeObject(\n            Object serializedObject\n            )\n        {\n            ArgumentNullException.ThrowIfNull(serializedObject);\n            FixedDocument fd = serializedObject as FixedDocument;\n            if( fd == null )\n            {\n\n               throw new ArgumentException(SR.ReachSerialization_ExpectedFixedDocument);\n            }\n            NgcSerializationManager ngcManager = SerializationManager as NgcSerializationManager;\n\n            ngcManager.StartDocument(fd,true);\n\n            ReachSerializer serializer = ngcManager.GetSerializer(fd.Pages);\n            serializer.SerializeObject(fd.Pages);\n\n            ngcManager.EndDocument();\n        }\n\n\n        /// <summary>\n        /// The method is called once the object data is discovered at that\n        /// point of the serialization process.\n        /// </summary>\n        /// <param name=\"serializableObjectContext\">\n        /// The context of the object to be serialized at this time.","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/NGCSerializer.cs#L69-L105","documentation":"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.","triggerScenarios":"Calling this SerializeObject overload with anything other than a FixedDocument instance (null is separately guarded) — e.g. a FixedPage, FixedDocumentSequence, or custom type.","commonSituations":"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.","solutions":["Pass a FixedDocument instance to this SerializeObject overload.","Use the FixedDocumentSequence serializer for sequences and the FixedPage serializer for pages.","Add an 'is FixedDocument' guard at the call site to fail with a clearer message."],"exampleFix":"// before\nfixedDocSerializer.SerializeObject(page); // page is FixedPage\n// after\nif (page is FixedDocument doc) fixedDocSerializer.SerializeObject(doc);\nelse pageSerializer.SerializeObject(page);","handlingStrategy":"type-guard","validationCode":"if (obj is not FixedDocument)\n    throw new ArgumentException(\"FixedDocument serializer requires a FixedDocument instance\");","typeGuard":"bool IsFixedDocument(object o) => o is FixedDocument;","tryCatchPattern":"try { serializer.SerializeObject(obj); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"FixedDocument\")) { /* route to the correct serializer for obj's actual type */ }","preventionTips":["Match serializer overloads to object types explicitly","Avoid passing object-typed variables to typed serializer overloads","Add compile-time overloads instead of runtime dispatch where possible"],"tags":["wpf","xps","argument","type-mismatch","serialization"],"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"}