{"record":{"id":"92af99b6a275c8dd","repo":"dotnet/wpf","slug":"sr-startnodemustbedocumentpagevieworfixedpage","errorCode":null,"errorMessage":"SR.StartNodeMustBeDocumentPageViewOrFixedPage","messagePattern":"SR\\.StartNodeMustBeDocumentPageViewOrFixedPage","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs","lineNumber":281,"sourceCode":"            else\n            {\n                // If we were passed a DPV because we are walking the visual tree,\n                // extract the DocumentPage from it;  its TextView will be used to\n                // turn coordinates into text positions\n                DocumentPageView dpv = startNode as DocumentPageView;\n                if (dpv != null)\n                {\n                    docPage = dpv.DocumentPage as FixedDocumentPage;\n                    if (docPage == null)\n                    {\n                        docPage = dpv.DocumentPage as FixedDocumentSequenceDocumentPage;\n                    }\n                }\n            }\n\n            if (docPage == null)\n            {\n                throw new ArgumentException(SR.StartNodeMustBeDocumentPageViewOrFixedPage, nameof(startNode));\n            }\n\n            ArgumentNullException.ThrowIfNull(locatorPart);\n\n            attachmentLevel = AttachmentLevel.Unresolved;\n\n            ITextView tv = (ITextView)((IServiceProvider)docPage).GetService(typeof(ITextView));\n            Debug.Assert(tv != null);\n\n            ReadOnlyCollection<TextSegment> ts = tv.TextSegments;\n\n            //check first if a TextRange can be generated\n            if (ts == null || ts.Count <= 0)\n                return null;\n\n            TextAnchor resolvedAnchor = new TextAnchor();\n\n            if (docPage != null)","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs#L263-L299","documentation":"FixedTextSelectionProcessor.ResolveLocatorPart resolves a ContentLocatorPart into a TextAnchor for annotations on FixedDocument content. The method receives a DependencyObject 'startNode' that must be a DocumentPageView or FixedPage; otherwise it cannot anchor the text. This ArgumentException is thrown when the start node is neither of those types.","triggerScenarios":"Calling ResolveLocatorPart with a locator part whose start node (DependencyObject) is a null docPage — i.e. the passed startNode is not a DocumentPageView or FixedPage (or its subtree failed to resolve to one).","commonSituations":"Passing the wrong visual (e.g. the FlowDocumentPageView, a ScrollViewer, or the AnnotationService host control) instead of the DocumentPageView that hosts fixed content; custom anchoring code that walks the visual tree and grabs an ancestor of the page view.","solutions":["Pass the DocumentPageView (for FixedDocument) or FixedPage that actually hosts the annotated content as startNode.","Verify the element type before calling: if (node is DocumentPageView || node is FixedPage) { ... }","Ensure the annotations are targeting FixedDocument/DocumentSequence content, not Flow content (use TextSelectionProcessor for flow)."],"exampleFix":"// before\nprocessor.ResolveLocatorPart(locatorPart, someVisual, out attachmentLevel);\n// after\nvar pageView = VisualTreeHelperExt.FindDescendant<DocumentPageView>(someVisual);\nprocessor.ResolveLocatorPart(locatorPart, pageView ?? throw new InvalidOperationException(\"No DocumentPageView in tree\"), out attachmentLevel);","handlingStrategy":"validation","validationCode":"if (startNode is not DocumentPageView and not FixedPage) throw new InvalidOperationException(\"startNode must be DocumentPageView or FixedPage\");","typeGuard":"bool IsValidStartNode(DependencyObject n) => n is DocumentPageView or FixedPage;","tryCatchPattern":"try { processor.ResolveLocatorPart(part, node, out var level); } catch (ArgumentException ex) { /* log: bad start node */ }","preventionTips":["Find the DocumentPageView via the visual tree before anchoring","Match processor to content type (fixed vs flow)","Never pass the service host control as startNode"],"tags":["wpf","annotations","argument-exception"],"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-22T01:17:13.364Z"}