{"record":{"id":"dde9228f017013bb","repo":"dotnet/wpf","slug":"sr-paginatormissingcontentposition","errorCode":null,"errorMessage":"SR.PaginatorMissingContentPosition","messagePattern":"SR\\.PaginatorMissingContentPosition","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Documents/DynamicDocumentPaginator.cs","lineNumber":76,"sourceCode":"        /// <summary>\n        /// Async version of <see cref=\"DynamicDocumentPaginator.GetPageNumber\"/>\n        /// </summary>\n        /// <param name=\"contentPosition\">Content position.</param>\n        /// <param name=\"userState\">Unique identifier for the asynchronous task.</param>\n        /// <exception cref=\"ArgumentException\">\n        /// Throws ArgumentException if the ContentPosition does not exist within \n        /// this element�s tree.\n        /// </exception>\n        public virtual void GetPageNumberAsync(ContentPosition contentPosition, object userState)\n        {\n            int pageNumber;\n\n            // Content position cannot be null.\n            ArgumentNullException.ThrowIfNull(contentPosition);\n            // Content position cannot be Missing.\n            if (contentPosition == ContentPosition.Missing)\n            {\n                throw new ArgumentException(SR.PaginatorMissingContentPosition, nameof(contentPosition));\n            }\n\n            pageNumber = GetPageNumber(contentPosition);\n            OnGetPageNumberCompleted(new GetPageNumberCompletedEventArgs(contentPosition, pageNumber, null, false, userState));\n        }\n\n        /// <summary>\n        /// Returns the ContentPosition for the given page.\n        /// </summary>\n        /// <param name=\"page\">Document page.</param>\n        /// <returns>Returns the ContentPosition for the given page.</returns>\n        /// <exception cref=\"ArgumentException\">\n        /// Throws ArgumentException if the page is not valid.\n        /// </exception>\n        public abstract ContentPosition GetPagePosition(DocumentPage page);\n\n        /// <summary>\n        /// Returns the ContentPosition for an object within the content.","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Documents/DynamicDocumentPaginator.cs#L58-L94","documentation":"DynamicDocumentPaginator.GetPageNumberAsync throws ArgumentException when the contentPosition parameter is ContentPosition.Missing (or null, via the preceding null check). Missing is a sentinel meaning 'no valid content position', not a real position that can be mapped to a page number, so it is rejected before calling GetPageNumber.","triggerScenarios":"Calling paginator.GetPageNumberAsync(contentPosition, userState) with ContentPosition.Missing, often obtained from an API that returned the Missing sentinel when the object is not yet in the document's content tree.","commonSituations":"Calling BringIntoView-style flows before the element is loaded into the document; passing ContentPosition.Missing from a failed GetContentPosition call; querying the page number of detached content.","solutions":["Check contentPosition != ContentPosition.Missing before calling GetPageNumberAsync","Ensure the content element is inserted into the document (e.g. inside the FixedDocument/FlowDocument) before querying its position","Handle the not-in-document case separately instead of calling the async API"],"exampleFix":"// before\npaginator.GetPageNumberAsync(element.ContentPosition, userState);\n// after\nvar pos = element.ContentPosition;\nif (pos != null && pos != ContentPosition.Missing)\n{\n    paginator.GetPageNumberAsync(pos, userState);\n}","handlingStrategy":"validation","validationCode":"if (contentPosition == null || contentPosition == ContentPosition.Missing)\n    throw new ArgumentException(\"contentPosition must be a valid position, not Missing.\", nameof(contentPosition));","typeGuard":"bool IsValidContentPosition(ContentPosition p) => p != null && !ReferenceEquals(p, ContentPosition.Missing);","tryCatchPattern":"try { paginator.GetPageNumberAsync(contentPosition, null); }\ncatch (ArgumentException) { /* content not in document; handle separately */ }","preventionTips":["Check for ContentPosition.Missing sentinel before any position-based API","Ensure content is inserted into the document before querying page numbers","Treat Missing as 'not in document' rather than a real position"],"tags":["wpf","argumentexception","documents","sentinel-value"],"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"}