{"record":{"id":"a0b94031dec27cdc","repo":"dotnet/wpf","slug":"sr-invalidstickynoteannotation","errorCode":null,"errorMessage":"SR.InvalidStickyNoteAnnotation","messagePattern":"SR\\.InvalidStickyNoteAnnotation","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs","lineNumber":1289,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// The method sets an instance of the IAttachedAnnotation to the StickyNoteControl.\n        /// It will be called by IAnnotationComponent.AddAttachedAnnotation.\n        /// </summary>\n        /// <param name=\"attachedAnnotation\">The instance of the IAttachedAnnotation</param>\n        private void SetAnnotation(IAttachedAnnotation attachedAnnotation)\n        {\n            SNCAnnotation sncAnnotation = new SNCAnnotation(attachedAnnotation.Annotation);\n\n            // Retrieve the data type. Then set the StickyNote to correct type.\n            // If we have empty data, we won't change the current StickyNote type.\n            bool hasInkData = sncAnnotation.HasInkData;\n            bool hasTextData = sncAnnotation.HasTextData;\n            if (hasInkData && hasTextData)\n            {\n                throw new ArgumentException(SR.InvalidStickyNoteAnnotation, nameof(attachedAnnotation));\n            }\n            else if (hasInkData)\n            {\n                _stickyNoteType = StickyNoteType.Ink;\n            }\n            else if (hasTextData)\n            {\n                _stickyNoteType = StickyNoteType.Text;\n            }\n\n            // If we already created a Content control, make sure it matches our new type or\n            // gets recreated to match.\n            if (Content != null)\n            {\n                EnsureStickyNoteType();\n            }\n\n            //create cargo if it is a new Annotation so it is not considered as new next time","sourceCodeStart":1271,"sourceCodeEnd":1307,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs#L1271-L1307","documentation":"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).","triggerScenarios":"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.","commonSituations":"Externally merged or corrupted annotation stores, annotation XML authored by other applications that allow both content types, migrating annotation streams between products.","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."],"exampleFix":"// before\n<!-- annotation payload -->\n<Ink>...</Ink><Text>hello</Text> <!-- both -> throws -->\n// after\n<Ink>...</Ink> <!-- keep exactly one content type -->","handlingStrategy":"validation","validationCode":"// before attaching, inspect payload: only one of <Ink> or <Text> must exist\nbool valid = !(annotation.Payload.Contents.SelectMany(c => c.Nodes()).OfType<XmlElement>()\n    .Count(e => e.LocalName is \"Ink\" or \"Text\") > 1);","typeGuard":null,"tryCatchPattern":"try { annotationService.LoadAnnotation(annotation); }\ncatch (ArgumentException ex) when (ex.ParamName == \"attachedAnnotation\") { /* quarantine/delete invalid annotation */ }","preventionTips":["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."],"tags":["wpf","annotations","stickynote","data-validation"],"backgroundTag":"schema-validation-failed","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"}