{"record":{"id":"695298de11ed7f73","repo":"dotnet/wpf","slug":"sr-addannotationsnotimplemented","errorCode":null,"errorMessage":"SR.AddAnnotationsNotImplemented","messagePattern":"SR\\.AddAnnotationsNotImplemented","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs","lineNumber":919,"sourceCode":"        /// </summary>\n        /// <param name=\"attachedAnnotation\">An IAttachedAnnotation instance</param>\n        void IAnnotationComponent.AddAttachedAnnotation(IAttachedAnnotation attachedAnnotation)\n        {\n            ArgumentNullException.ThrowIfNull(attachedAnnotation);\n\n            if (_attachedAnnotation == null)\n            {\n                //fire trace event\n                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedSNBegin);\n\n                SetAnnotation(attachedAnnotation);\n\n                //fire trace event\n                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedSNEnd);\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.AddAnnotationsNotImplemented);\n            }\n        }\n\n        /// <summary>\n        /// Removes an attached annotations from this StickyNoteControl.\n        /// </summary>\n        /// <param name=\"attachedAnnotation\">An IAttachedAnnotation instance</param>\n        void IAnnotationComponent.RemoveAttachedAnnotation(IAttachedAnnotation attachedAnnotation)\n        {\n            ArgumentNullException.ThrowIfNull(attachedAnnotation);\n\n            if (attachedAnnotation == _attachedAnnotation)\n            {\n                //fire trace event\n                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.RemoveAttachedSNBegin);\n\n                GiveUpFocus();\n","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs#L901-L937","documentation":"StickyNoteControl.AddAttachedAnnotation only supports adding annotations whose anchor component is this StickyNote (annotation loaded from the AnnotationService store); it throws InvalidOperationException('AddAnnotationsNotImplemented') for any other input path. The method exists to implement the IAnnotationComponent interface, not as a general API for programmatically creating annotations.","triggerScenarios":"Calling StickyNoteControl.AddAttachedAnnotation (explicitly or via the IAnnotationComponent interface) with an attached annotation that is not being loaded by the AnnotationService/AnnotationComponentManager for this StickyNote.","commonSituations":"Application code trying to create annotations on a StickyNote programmatically instead of using AnnotationService.CreateHighlightForSelection, or calling the interface method directly after loading annotations from a stream.","solutions":["Do not call AddAttachedAnnotation directly; use AnnotationService (CreateHighlightForSelection/CreateTextStickyNoteForSelection) to create annotations.","Let AnnotationService/AnnotationComponentManager load annotations from the annotation store, which is the only supported path.","If you need custom anchors, implement a custom IAnnotationComponent and register it via AnnotationComponentManager rather than reusing StickyNoteControl's.","Check that AnnotationService is enabled on the FlowDocumentPageViewer/DocumentViewer hosting the StickyNote before expecting annotation loading."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only let AnnotationService load annotations; if calling directly, verify the annotation was loaded by AnnotationComponentManager first","typeGuard":null,"tryCatchPattern":"try { stickyNote.AddAttachedAnnotation(attachedAnnotation); }\ncatch (InvalidOperationException) { annotationService.CreateTextStickyNoteForSelection(anchorId, ...); }","preventionTips":["Use AnnotationService APIs (CreateTextStickyNoteForSelection etc.) instead of the component interface.","Treat IAnnotationComponent.AddAttachedAnnotation as infrastructure, not app API.","Ensure AnnotationService is enabled on the hosting viewer so annotations load through the supported path."],"tags":["wpf","annotations","stickynote"],"backgroundTag":"method-not-implemented","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"}