dotnet/wpf · error · NotSupportedException

SR.NotSupported

Error message

SR.NotSupported

What it means

StickyNoteControl's explicit IAnnotationComponent.ModifyAttachedAnnotation implementation deliberately throws NotSupportedException(SR.NotSupported). Modifications to attached annotations on a StickyNote arrive through a different internal path (anchor updates), so the interface method is intentionally unimplemented.

Solutions

  1. Do not call ModifyAttachedAnnotation on StickyNoteControl; handle modifications via the annotation store / AnnotationService events instead.
  2. Check the component type (if (component is StickyNoteControl)) and route modification differently.
  3. Implement your own IAnnotationComponent for modify-capable annotation UIs.
  4. Wrap interface-driven modification loops in try/catch (NotSupportedException) for components that declare it unsupported.

Example fix

// before
((IAnnotationComponent)stickyNote).ModifyAttachedAnnotation(aa, prevAnchor, prevLevel);
// after
if (stickyNote is IAnnotationComponent comp && !(stickyNote is StickyNoteControl))
    comp.ModifyAttachedAnnotation(aa, prevAnchor, prevLevel);
Defensive patterns

Strategy: try-catch

Validate before calling

bool modifiesSupported = !(component is StickyNoteControl);

Type guard

static bool SupportsModify(IAnnotationComponent c) => c is not StickyNoteControl;

Try / catch

try { component.ModifyAttachedAnnotation(aa, prevAnchor, prevLevel); }
catch (NotSupportedException) { /* StickyNote ignores modify; route via annotation store */ }

Prevention

When it happens

Trigger: Any call to IAnnotationComponent.ModifyAttachedAnnotation on a StickyNoteControl, e.g. from custom annotation framework code that drives components through the IAnnotationComponent contract.

Common situations: Custom AnnotationComponent code iterating all components and calling ModifyAttachedAnnotation uniformly, ported annotation code that assumed StickyNote supports the full IAnnotationComponent surface.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/4a33a4cae409408a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs:957

                //fire trace event
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.RemoveAttachedSNEnd);
            }
            else
            {
                throw new ArgumentException(SR.InvalidValueSpecified, nameof(attachedAnnotation));
            }
        }

        /// <summary>
        /// Called when an AttachedAnnotation's attached anchor changes.
        /// </summary>
        /// <param name="attachedAnnotation">The attached annotation after modification</param>
        /// <param name="previousAttachedAnchor">The attached anchor previously associated with the attached annotation.</param>
        /// <param name="previousAttachmentLevel">The previous attachment level of the attached annotation.</param>
        void IAnnotationComponent.ModifyAttachedAnnotation(IAttachedAnnotation attachedAnnotation, object previousAttachedAnchor, AttachmentLevel previousAttachmentLevel)
        {
            throw new NotSupportedException(SR.NotSupported);
        }

        /// <summary>
        /// Gets the attached annotations this component is representing.
        /// </summary>
        /// <returns>list of IAttachedAnnotation instances this component is representing</returns>
        IList IAnnotationComponent.AttachedAnnotations
        {
            get
            {
                ArrayList annotations = new ArrayList(1);

                if (_attachedAnnotation != null)
                {
                    annotations.Add(_attachedAnnotation);
                }

                return annotations;

View on GitHub (pinned to 81131a70a4)