{"record":{"id":"f0e64abf00d8002d","repo":"dotnet/wpf","slug":"sr-documentpageview-parentnotdocumentpagehost","errorCode":null,"errorMessage":"SR.DocumentPageView_ParentNotDocumentPageHost","messagePattern":"SR\\.DocumentPageView_ParentNotDocumentPageHost","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageHost.cs","lineNumber":55,"sourceCode":"        //\n        //  Internal Methods\n        //\n        //-------------------------------------------------------------------\n\n        #region Internal Methods\n\n        internal static void DisconnectPageVisual(Visual pageVisual)\n        {\n            // There might be a case where a visual associated with a page was \n            // inserted to a visual tree before. It got removed later, but GC did not\n            // destroy its parent yet. To workaround this case always check for the parent\n            // of page visual and disconnect it, when necessary.\n            Visual currentParent = VisualTreeHelper.GetParent(pageVisual) as Visual;\n            if (currentParent != null)\n            {\n                ContainerVisual pageVisualHost = currentParent as ContainerVisual;\n                if (pageVisualHost == null)\n                    throw new ArgumentException(SR.DocumentPageView_ParentNotDocumentPageHost, nameof(pageVisual));\n                DocumentPageHost docPageHost = VisualTreeHelper.GetParent(pageVisualHost) as DocumentPageHost;\n                if (docPageHost == null)\n                    throw new ArgumentException(SR.DocumentPageView_ParentNotDocumentPageHost, nameof(pageVisual));\n                docPageHost.PageVisual = null;\n            }\n        }\n\n        #endregion Internal Methods\n\n        //-------------------------------------------------------------------\n        //\n        //  Internal Properties\n        //\n        //-------------------------------------------------------------------\n\n        #region Internal Properties\n\n        /// <summary>","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageHost.cs#L37-L73","documentation":"ArgumentException (DocumentPageView_ParentNotDocumentPageHost) from DocumentPageHost.DisconnectPageVisual: the parent chain management encountered a page visual whose parent is not the expected DocumentPageHost, i.e. the page visual was re-parented externally, so disconnecting would corrupt the tree.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageHost.cs:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Let the document viewer manage page visual parenting; do not add page visuals to other trees","Call the disconnect path only while the page host still owns the visual"],"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"}