{"record":{"id":"e83cef659d0a68eb","repo":"dotnet/wpf","slug":"sr-idpinvalidcontentposition-documentsequence","errorCode":null,"errorMessage":"SR.IDPInvalidContentPosition","messagePattern":"SR\\.IDPInvalidContentPosition","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs","lineNumber":324,"sourceCode":"        internal int GetPageNumber(ContentPosition contentPosition)\n        {\n            ArgumentNullException.ThrowIfNull(contentPosition);\n\n            // ContentPosition may be only created by DynamicDocumentPaginator.GetObjectPosition or\n            // DynamicDocumentPaginator.GetPagePosition.\n            // Because of that we are expecting one of 2 types here.\n            DynamicDocumentPaginator childPaginator = null;\n            ContentPosition childContentPosition = null;\n            if (contentPosition is DocumentSequenceTextPointer dsTextPointer)\n            {\n\n                childPaginator = GetPaginator(dsTextPointer.ChildBlock.DocRef);\n                childContentPosition = dsTextPointer.ChildPointer as ContentPosition;\n            }\n\n            if (childContentPosition == null)\n            {\n                throw new ArgumentException(SR.IDPInvalidContentPosition);\n            }\n\n            int childPageNumber = childPaginator.GetPageNumber(childContentPosition);\n            int pageNumber;\n            _SynthesizeGlobalPageNumber(childPaginator, childPageNumber, out pageNumber);\n            return pageNumber;\n        }\n\n        /// <summary>\n        /// <see cref=\"System.Windows.Documents.DocumentPaginator.CancelAsync\"/>\n        /// </summary>\n        internal void CancelAsync(object userState)\n        {\n            DocumentsTrace.FixedFormat.IDF.Trace($\"IDP.GetPageAsyncCancel([{userState}])\");\n\n            ArgumentNullException.ThrowIfNull(userState);\n\n            if (_asyncOps.ContainsKey(userState))","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs#L306-L342","documentation":"DocumentSequence's GetPageNumber resolves a ContentPosition back to a page number by splitting the sequence text pointer into a child paginator and child ContentPosition. If the child content position cannot be extracted (null), it throws ArgumentException with SR.IDPInvalidContentPosition — the object is not a content position belonging to this document sequence.","triggerScenarios":"Calling GetPageNumber with a ContentPosition from a different document/paginator, a stale or disposed ContentPosition, or ContentPosition.Null obtained from an earlier failed GetPage.","commonSituations":"Mixing ContentPositions between multiple document viewers/paginators; caching a ContentPosition across document reloads; passing ContentPosition.Null; using a position from a child FixedDocument directly with the sequence paginator.","solutions":["Only pass ContentPositions obtained from this same FixedDocumentSequence paginator (e.g. from GetPage(...).ContentPosition)","Re-fetch the ContentPosition after the document is reloaded instead of caching stale ones","Handle ContentPosition.Null explicitly and skip the GetPageNumber call","Use a TextPointer/Logical tree position from the sequence itself when resolving"],"exampleFix":"// before\nint page = sequencePaginator.GetPageNumber(otherDocPage.ContentPosition);\n// after\nvar seqPage = sequencePaginator.GetPage(i);\nint page = sequencePaginator.GetPageNumber(seqPage.ContentPosition);","handlingStrategy":"type-guard","validationCode":"if (contentPosition == null || contentPosition == ContentPosition.Null) return -1;","typeGuard":"static bool IsValidContentPosition(ContentPosition cp) => cp != null && cp != ContentPosition.Null;","tryCatchPattern":"try { int page = paginator.GetPageNumber(cp); } catch (ArgumentException) { page = -1; }","preventionTips":["Only use ContentPositions from the same paginator","Never cache positions across reloads","Treat ContentPosition.Null explicitly"],"tags":["wpf","pagination","content-position"],"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"}