{"record":{"id":"272aa79db1d4750d","repo":"dotnet/wpf","slug":"sr-parametermustbelogicalnode","errorCode":null,"errorMessage":"SR.ParameterMustBeLogicalNode","messagePattern":"SR\\.ParameterMustBeLogicalNode","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs","lineNumber":134,"sourceCode":"            ArgumentNullException.ThrowIfNull(viewer);\n\n            Initialize(viewer);\n        }\n\n\n        /// <summary>\n        ///     Creates an instance of the AnnotationService focused on a particular\n        ///     tree node.\n        /// </summary>\n        /// <param name=\"root\">the tree node this service will operate on</param>\n        /// <exception cref=\"ArgumentNullException\">root is null</exception>\n        /// <exception cref=\"ArgumentException\">element is not a FrameworkElement or FrameworkContentElement</exception>\n        internal AnnotationService(DependencyObject root)\n        {\n            ArgumentNullException.ThrowIfNull(root);\n\n            if (!(root is FrameworkElement || root is FrameworkContentElement))\n                throw new ArgumentException(SR.ParameterMustBeLogicalNode, nameof(root));\n\n            Initialize(root);\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------\n\n        #region Public Methods\n\n        /// <summary>\n        ///     Enables the service with the given store.\n        /// </summary>\n        /// <param name=\"annotationStore\">store to use for retreiving and persisting annotations</param>","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs#L116-L152","documentation":"The internal AnnotationService(DependencyObject) constructor throws ArgumentException when the root is neither a FrameworkElement nor a FrameworkContentElement. The annotation service attaches to the logical tree, so the root must be a logical node that can host annotation attached properties and resolve IServiceProvider. Public entry points like AnnotationService.Enable/Disable call this with the viewer, so passing an arbitrary DependencyObject fails.","triggerScenarios":"Constructing an AnnotationService with a DependencyObject that is not part of a logical tree — e.g. a DispatcherObject, an AnimationClock, a raw Visual that is not a FrameworkElement, or a FrameworkContentElement-less content node.","commonSituations":"Attempting to enable annotations on unsupported hosts (custom viewers, ItemsControl items, free visuals); passing a DependencyObject from reflection or generic plumbing code; wiring annotations to non-WPF-framework objects.","solutions":["Pass a supported viewer such as DocumentViewer, FlowDocumentPageViewer, FlowDocumentScrollViewer, or FlowDocumentReader as the root.","Ensure the DependencyObject is a FrameworkElement or FrameworkContentElement before constructing/enabling the service.","Use the public AnnotationService.Enable(service, viewer) path with a supported DocumentViewerBase/FlowDocumentScrollViewer.","If annotating custom content, wrap it in a supported viewer rather than passing the raw object."],"exampleFix":"// before\nvar service = new AnnotationService(myVisual as DependencyObject);\n\n// after\nif (myVisual is FrameworkElement fe)\n{\n    var service = new AnnotationService(fe);\n}","handlingStrategy":"type-guard","validationCode":"if (!(root is FrameworkElement) && !(root is FrameworkContentElement))\n    throw new ArgumentException(\"root must be a logical tree node\");","typeGuard":"bool CanHostAnnotationService(DependencyObject o) =>\n    o is FrameworkElement or FrameworkContentElement;","tryCatchPattern":"try { var service = new AnnotationService(root); service.Enable(store); }\ncatch (ArgumentException) { /* use a supported viewer host instead */ }","preventionTips":["Only enable annotations on supported viewers (DocumentViewerBase, FlowDocumentReader, FlowDocumentScrollViewer).","Assert the host is FrameworkElement/FrameworkContentElement before construction.","Do not pass raw Visuals or non-framework DependencyObjects to annotation APIs."],"tags":["wpf","annotations","type-mismatch","argumentexception"],"backgroundTag":"incompatible-source-type","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"}