{"record":{"id":"09e2498e45283dd1","repo":"dotnet/wpf","slug":"sr-idpnegativepagenumber-documentsequence","errorCode":null,"errorMessage":"SR.IDPNegativePageNumber","messagePattern":"SR\\.IDPNegativePageNumber","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs","lineNumber":241,"sourceCode":"\n        #endregion IDocumentPaginatorSource Members\n\n        #region DocumentPaginator\n\n        /// <summary>\n        /// <see cref=\"System.Windows.Documents.DocumentPaginator.GetPage\"/>\n        /// </summary>\n        internal DocumentPage GetPage(int pageNumber)\n        {\n            DocumentsTrace.FixedFormat.IDF.Trace($\"IDP.GetPage({pageNumber})\");\n\n            // Make sure that the call is in the right context.\n//             Dispatcher.VerifyAccess();\n\n            // Page number cannot be negative.\n            if (pageNumber < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(pageNumber), SR.IDPNegativePageNumber);\n            }\n\n            DocumentPage innerDP = null;\n            DynamicDocumentPaginator innerPaginator;\n            int innerPageNumber;\n            // Find the appropriate inner IDF and BR\n            if (TranslatePageNumber(pageNumber, out innerPaginator, out innerPageNumber))\n            {\n                innerDP = innerPaginator.GetPage(innerPageNumber);\n                Debug.Assert(innerDP != null);\n\n                // Now warp inner DP and return it\n                return new FixedDocumentSequenceDocumentPage(this, innerPaginator, innerDP);\n            }\n            return DocumentPage.Missing;\n        }\n\n        /// <summary>","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequence.cs#L223-L259","documentation":"DocumentSequenceDocumentPage's GetPage validates that the requested global page number is not negative and throws ArgumentOutOfRangeException with SR.IDPNegativePageNumber. Page numbers are zero-based across the whole FixedDocumentSequence.","triggerScenarios":"Calling GetPage(pageNumber) on the FixedDocumentSequence's paginator (e.g. via DocumentViewer's docPage path) with a negative int, typically from a bad computation like index-1 before bounds checks or an uninitialized counter.","commonSituations":"Off-by-one arithmetic computing the page to jump to; storing page indices in state and passing an uninitialized (-1) value; user-supplied page number parsed without validation.","solutions":["Clamp or validate the page number is >= 0 before calling GetPage","Guard state that may hold -1/uninitialized values (e.g. 'no page selected')","Validate user input page numbers before use","Use DocumentPaginator.PageCount to bound computed page indices"],"exampleFix":"// before\nvar page = paginator.GetPage(selectedIndex - 1);\n// after\nif (selectedIndex > 0)\n    var page = paginator.GetPage(selectedIndex - 1);","handlingStrategy":"validation","validationCode":"if (pageNumber < 0 || pageNumber >= paginator.PageCount) return null;","typeGuard":null,"tryCatchPattern":"try { var page = paginator.GetPage(pageNumber); } catch (ArgumentOutOfRangeException) { page = null; }","preventionTips":["Clamp page indices to [0, PageCount-1]","Initialize stored page indices to 0, not -1","Validate parsed user input page numbers"],"tags":["wpf","pagination","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}