{"record":{"id":"15d29ab85b3e7ca4","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-value-gettype-typeof-15d29a","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(DocumentReference))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, value\\.GetType\\(\\), typeof\\(DocumentReference\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs","lineNumber":101,"sourceCode":"        #region IAddChild\n\n        ///<summary>\n        /// Called to Add the object as a Child.\n        ///</summary>\n        ///<param name=\"value\">\n        /// Object to add as a child\n        ///</param>\n        void IAddChild.AddChild(Object value)\n        {\n            ArgumentNullException.ThrowIfNull(value);\n\n//             Dispatcher.VerifyAccess();\n\n            DocumentReference docRef = value as DocumentReference;\n\n            if (docRef == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(DocumentReference)), nameof(value));\n            }\n\n            if (docRef.IsInitialized)\n            {\n                _references.Add(docRef);\n            }\n            else\n            {\n                DocumentsTrace.FixedDocumentSequence.Content.Trace($\"Doc {_references.Count} Deferred\");\n                if (_partialRef == null)\n                {\n                    _partialRef = docRef;\n                    _partialRef.Initialized += new EventHandler(_OnDocumentReferenceInitialized);\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.PrevoiusUninitializedDocumentReferenceOutstanding);\n                }","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs#L83-L119","documentation":"DocumentSequence.AddChild implements IAddChild and only accepts DocumentReference children. If the value passed cannot be cast to DocumentReference, it throws ArgumentException with SR.UnexpectedParameterType. DocumentSequence markup/child collections must contain only <DocumentReference> elements.","triggerScenarios":"Calling AddChild directly with a non-DocumentReference object; putting an element other than DocumentReference inside a FixedDocumentSequence in XAML so the parser calls AddChild with the wrong type.","commonSituations":"Hand-editing XAML and nesting a FixedDocument or PageContent directly under FixedDocumentSequence instead of DocumentReference; programmatic document construction adding pages directly to the sequence.","solutions":["Only add DocumentReference instances to a DocumentSequence","In XAML, wrap each child FixedDocument in a <DocumentReference> element","If building programmatically, create a DocumentReference, set its Source (or Id/Document), then call AddChild","Move unrelated children (styles, resources) out of the FixedDocumentSequence element"],"exampleFix":"// before\nfixedDocumentSequence.AddChild(fixedDocument);\n// after\nvar docRef = new DocumentReference();\ndocRef.Document = fixedDocument;\nfixedDocumentSequence.AddChild(docRef);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsDocumentReference(object value) => value is DocumentReference;","tryCatchPattern":"if (docRef is DocumentReference r) fixedDocumentSequence.AddChild(r); else throw new ArgumentException(nameof(docRef));","preventionTips":["Only wrap FixedDocument children in DocumentReference in XAML","Never call IAddChild.AddChild directly with foreign objects","Keep styles/resources outside the FixedDocumentSequence children"],"tags":["wpf","xaml","type-mismatch"],"backgroundTag":"type-mismatch","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"}