dotnet/wpf · error · InvalidOperationException
SR.AddAnnotationsNotImplemented
Error message
SR.AddAnnotationsNotImplemented
What it means
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.
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Only let AnnotationService load annotations; if calling directly, verify the annotation was loaded by AnnotationComponentManager first
Try / catch
try { stickyNote.AddAttachedAnnotation(attachedAnnotation); }
catch (InvalidOperationException) { annotationService.CreateTextStickyNoteForSelection(anchorId, ...); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SR.InvalidStickyNoteAnnotation
- anchorLocator.Parts
- annotation component
- InvalidEnumArgumentException("action", (int)action…
- InvalidEnumArgumentException("action", (int)action…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/695298de11ed7f73.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs:919
/// </summary>
/// <param name="attachedAnnotation">An IAttachedAnnotation instance</param>
void IAnnotationComponent.AddAttachedAnnotation(IAttachedAnnotation attachedAnnotation)
{
ArgumentNullException.ThrowIfNull(attachedAnnotation);
if (_attachedAnnotation == null)
{
//fire trace event
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedSNBegin);
SetAnnotation(attachedAnnotation);
//fire trace event
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.AddAttachedSNEnd);
}
else
{
throw new InvalidOperationException(SR.AddAnnotationsNotImplemented);
}
}
/// <summary>
/// Removes an attached annotations from this StickyNoteControl.
/// </summary>
/// <param name="attachedAnnotation">An IAttachedAnnotation instance</param>
void IAnnotationComponent.RemoveAttachedAnnotation(IAttachedAnnotation attachedAnnotation)
{
ArgumentNullException.ThrowIfNull(attachedAnnotation);
if (attachedAnnotation == _attachedAnnotation)
{
//fire trace event
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.RemoveAttachedSNBegin);
GiveUpFocus();
View on GitHub (pinned to 81131a70a4)