{"record":{"id":"2e44e509cbb5df1a","repo":"dotnet/wpf","slug":"sr-invalidvaluespecified","errorCode":null,"errorMessage":"SR.InvalidValueSpecified","messagePattern":"SR\\.InvalidValueSpecified","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs","lineNumber":945,"sourceCode":"        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\n                ClearAnnotation();\n\n                //fire trace event\n                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.RemoveAttachedSNEnd);\n            }\n            else\n            {\n                throw new ArgumentException(SR.InvalidValueSpecified, nameof(attachedAnnotation));\n            }\n        }\n\n        /// <summary>\n        /// Called when an AttachedAnnotation's attached anchor changes.\n        /// </summary>\n        /// <param name=\"attachedAnnotation\">The attached annotation after modification</param>\n        /// <param name=\"previousAttachedAnchor\">The attached anchor previously associated with the attached annotation.</param>\n        /// <param name=\"previousAttachmentLevel\">The previous attachment level of the attached annotation.</param>\n        void IAnnotationComponent.ModifyAttachedAnnotation(IAttachedAnnotation attachedAnnotation, object previousAttachedAnchor, AttachmentLevel previousAttachmentLevel)\n        {\n            throw new NotSupportedException(SR.NotSupported);\n        }\n\n        /// <summary>\n        /// Gets the attached annotations this component is representing.\n        /// </summary>\n        /// <returns>list of IAttachedAnnotation instances this component is representing</returns>","sourceCodeStart":927,"sourceCodeEnd":963,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteAnnotations.cs#L927-L963","documentation":"StickyNoteControl.RemoveAttachedAnnotation throws ArgumentException('InvalidValueSpecified', paramName 'attachedAnnotation') when the passed IAttachedAnnotation is not one this StickyNote currently holds in its _attachedAnnotation cache. Only annotations the component has actually attached (loaded via AnnotationService) can be removed.","triggerScenarios":"Calling StickyNoteControl.RemoveAttachedAnnotation with a null value, with an IAttachedAnnotation created elsewhere, or with one belonging to a different StickyNoteControl instance.","commonSituations":"Programmatic removal of annotations from the wrong StickyNote, holding stale IAttachedAnnotation references after the annotation store was reloaded, or passing an annotation whose anchor no longer resolves.","solutions":["Verify the attachedAnnotation is non-null and was previously added to this StickyNoteControl (compare with the items exposed by GetAttachedAnnotations).","Remove annotations through AnnotationService.DeleteAnnotationStore / annotation store APIs using the annotation Id instead of the component method.","Reload or re-resolve the IAttachedAnnotation if it is stale after the annotation store changed.","Guard the call: only invoke after confirming the annotation belongs to this StickyNote's annotation list."],"exampleFix":"// before\nstickyNote.RemoveAttachedAnnotation(unknownAnnotation);\n// after\nif (stickyNote.GetAttachedAnnotations().Contains(unknownAnnotation))\n    stickyNote.RemoveAttachedAnnotation(unknownAnnotation);","handlingStrategy":"validation","validationCode":"bool canRemove = attachedAnnotation != null && stickyNote.GetAttachedAnnotations().Contains(attachedAnnotation);","typeGuard":"static bool BelongsToStickyNote(StickyNoteControl sn, IAttachedAnnotation aa) =>\n    aa != null && sn.GetAttachedAnnotations().Contains(aa);","tryCatchPattern":"try { stickyNote.RemoveAttachedAnnotation(attachedAnnotation); }\ncatch (ArgumentException) { /* annotation not attached to this StickyNote; use annotation store APIs */ }","preventionTips":["Track which IAttachedAnnotation instances came from this StickyNote before removing.","Use AnnotationService/annotation-store deletion (by annotation Id) as the primary removal path.","Refresh cached annotations after any store reload."],"tags":["wpf","annotations","argument"],"backgroundTag":"invalid-argument-value","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"}