{"record":{"id":"a89f6117c30cac55","repo":"dotnet/wpf","slug":"sr-rowcacherecalcwithnopagecache","errorCode":null,"errorMessage":"SR.RowCacheRecalcWithNoPageCache","messagePattern":"SR\\.RowCacheRecalcWithNoPageCache","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/RowCache.cs","lineNumber":441,"sourceCode":"                    break;\n                }\n\n                //This row is visible, add it to the count.\n                rowCount++;\n            }\n        }\n\n        /// <summary>\n        /// Recalculates the current row layout by applying the current Scale\n        /// and PageSpacing to the current row layout.  It does not change the\n        /// contents of the rows.\n        /// </summary>\n        public void RecalcLayoutForScaleOrSpacing()\n        {\n            //Throw execption if we have no PageCache\n            if (PageCache == null)\n            {\n                throw new InvalidOperationException(SR.RowCacheRecalcWithNoPageCache);\n            }\n\n            //Reset the extents\n            _extentWidth = 0.0;\n            _extentHeight = 0.0;\n\n            //Walk through each row and based on the pages on the row,\n            //recalculate the width and height of the row.\n            double currentOffset = 0.0;\n            for (int i = 0; i < _rowCache.Count; i++)\n            {\n                //Get this row and save off the page count.\n                RowInfo currentRow = _rowCache[i];\n                int pageCount = currentRow.PageCount;\n\n                //Clear the pages so we can add the new, rescaled ones.\n                currentRow.ClearPages();\n                currentRow.VerticalOffset = currentOffset;","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/RowCache.cs#L423-L459","documentation":"RowCache.RecalcLayoutForScaleOrSpacing recomputes row extents after zoom scale or page spacing changes. It requires an associated PageCache (PageCache property); when none is set, InvalidOperationException(SR.RowCacheRecalcWithNoPageCache) is thrown because extents cannot be computed without page sizes.","triggerScenarios":"Changing Scale, HorizontalPageSpacing, or VerticalPageSpacing on a RowCache that was constructed without (or before being given) a PageCache, causing RecalcLayoutForScaleOrSpacing to run with PageCache == null.","commonSituations":"Binding zoom/spacing properties on a MultiPage viewer before the document (and its PageCache) is assigned; constructing RowCache manually in custom viewer controls and tweaking layout properties during initialization.","solutions":["Set/assign the PageCache (document) before changing Scale or spacing properties.","Guard property setters: skip recalculation when PageCache is null until the document is loaded.","Defer zoom/spacing initialization to the document-loaded event rather than the control constructor.","Verify the viewer's Document dependency property is bound before applying saved layout settings."],"exampleFix":"// before\nrowCache.Scale = savedZoom; // PageCache not yet assigned\n// after\nif (rowCache.PageCache != null)\n{\n    rowCache.Scale = savedZoom;\n}","handlingStrategy":"validation","validationCode":"if (rowCache.PageCache != null)\n{\n    rowCache.Scale = zoom;\n}","typeGuard":"bool HasPageCache(RowCache rc) => rc?.PageCache != null;","tryCatchPattern":"try { rowCache.RecalcLayoutForScaleOrSpacing(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"PageCache\"))\n{\n    // document not yet assigned: defer recalc until load completes\n}","preventionTips":["Assign the document/PageCache before applying zoom or spacing settings","Apply saved layout settings on DocumentLoaded, not in constructors","Null-check PageCache in property setters of custom viewers"],"tags":["wpf","row-cache","missing-dependency","invalid-state"],"backgroundTag":"invalid-state-transition","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"}