{"record":{"id":"0705f1ce68f194d6","repo":"dotnet/wpf","slug":"sr-documentgridinvalidviewmode","errorCode":null,"errorMessage":"SR.DocumentGridInvalidViewMode","messagePattern":"SR\\.DocumentGridInvalidViewMode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs","lineNumber":2456,"sourceCode":"                    //If we have no space to display pages, there's nothing to scale.\n                    //So just return 1.0 to indicate no change.\n                    if (thumbnailCompensatedViewportHeight <= 0.0)\n                    {\n                        scaleFactor = 1.0;\n                    }\n                    else\n                    {\n                        scaleFactor = Math.Min(compensatedViewportWidth / rowWidth,\n                            thumbnailCompensatedViewportHeight / thumbnailCompensatedExtentHeight);\n                    }\n                    break;\n\n                case ViewMode.Zoom:\n                    //We will not change the scale here, as this is not a \"page-fit\" mode.\n                    break;\n\n                default:\n                    throw new InvalidOperationException(SR.DocumentGridInvalidViewMode);\n            }\n\n            return scaleFactor;\n        }\n\n        /// <summary>\n        /// Creates the caches used by DocumentGrid, and sets default property values.\n        /// </summary>\n        private void Initialize()\n        {\n            //Create our caches\n            _pageCache = new PageCache();\n            _childrenCollection = new VisualCollection(this);\n\n            _rowCache = new RowCache\n            {\n                PageCache = _pageCache\n            };","sourceCodeStart":2438,"sourceCodeEnd":2474,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs#L2438-L2474","documentation":"ArgumentException sentinel from DocumentGrid: an unrecognized ViewMode value reached internal layout logic (the enum switch's default case), i.e. the view mode is outside the supported set, so layout cannot compute a scale factor.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:2456 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set ViewMode using DocumentViewMode enum values rather than raw casts","Validate externally supplied mode values against the known enum before assigning"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}