dotnet/wpf · error · ArgumentException
SR.InvalidStickyNoteAnnotation
Error message
SR.InvalidStickyNoteAnnotation
What it means
When a StickyNoteControl binds to an annotation (AttachAnnotation path), the annotation's payload must be either ink or text, not both. If XmlAnnotation.HasInkData and HasTextData are both true, the constructor throws ArgumentException('InvalidStickyNoteAnnotation', 'attachedAnnotation') because a StickyNote can only be one StickyNoteType (Ink or Text).
Solutions
- Repair the annotation payload so it contains exactly one of Ink or Text content, then reload it in AnnotationService.
- Delete the invalid annotation from the annotation store and recreate it with AnnotationService.
- Sanitize annotation XML (strip one content type) when importing annotations from external sources.
- Catch ArgumentException during AttachAnnotation/annotation loading and quarantine the offending annotation instead of crashing the load.
Example fix
// before <!-- annotation payload --> <Ink>...</Ink><Text>hello</Text> <!-- both -> throws --> // after <Ink>...</Ink> <!-- keep exactly one content type -->
Defensive patterns
Strategy: validation
Validate before calling
// before attaching, inspect payload: only one of <Ink> or <Text> must exist
bool valid = !(annotation.Payload.Contents.SelectMany(c => c.Nodes()).OfType<XmlElement>()
.Count(e => e.LocalName is "Ink" or "Text") > 1); Try / catch
try { annotationService.LoadAnnotation(annotation); }
catch (ArgumentException ex) when (ex.ParamName == "attachedAnnotation") { /* quarantine/delete invalid annotation */ } Prevention
- Sanitize annotation XML on import: keep exactly one of Ink or Text payload.
- Never hand-edit annotation store files.
- Quarantine invalid annotations instead of aborting the whole store load.
When it happens
Trigger: Loading/attaching an annotation whose StickyNote payload XML contains both an Ink AND a Text node, e.g. annotation data written by non-WPF tooling or hand-edited annotation store files.
Common situations: Externally merged or corrupted annotation stores, annotation XML authored by other applications that allow both content types, migrating annotation streams between products.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.AddAnnotationsNotImplemented
- 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/a0b94031dec27cdc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs:1289
}
}
/// <summary>
/// The method sets an instance of the IAttachedAnnotation to the StickyNoteControl.
/// It will be called by IAnnotationComponent.AddAttachedAnnotation.
/// </summary>
/// <param name="attachedAnnotation">The instance of the IAttachedAnnotation</param>
private void SetAnnotation(IAttachedAnnotation attachedAnnotation)
{
SNCAnnotation sncAnnotation = new SNCAnnotation(attachedAnnotation.Annotation);
// Retrieve the data type. Then set the StickyNote to correct type.
// If we have empty data, we won't change the current StickyNote type.
bool hasInkData = sncAnnotation.HasInkData;
bool hasTextData = sncAnnotation.HasTextData;
if (hasInkData && hasTextData)
{
throw new ArgumentException(SR.InvalidStickyNoteAnnotation, nameof(attachedAnnotation));
}
else if (hasInkData)
{
_stickyNoteType = StickyNoteType.Ink;
}
else if (hasTextData)
{
_stickyNoteType = StickyNoteType.Text;
}
// If we already created a Content control, make sure it matches our new type or
// gets recreated to match.
if (Content != null)
{
EnsureStickyNoteType();
}
//create cargo if it is a new Annotation so it is not considered as new next timeView on GitHub (pinned to 81131a70a4)