{"record":{"id":"38eb01823bf116fe","repo":"dotnet/wpf","slug":"sr-format-sr-nothighlightannotationtype-attachedannotation","errorCode":null,"errorMessage":"SR.Format(SR.NotHighlightAnnotationType, attachedAnnotation.Annotation.AnnotationType.ToString())","messagePattern":"SR\\.Format\\(SR\\.NotHighlightAnnotationType, attachedAnnotation\\.Annotation\\.AnnotationType\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/HighlightComponent.cs","lineNumber":528,"sourceCode":"            if (textAnchor == null)\n            {\n                throw new ArgumentException(SR.InvalidAttachedAnchor, nameof(attachedAnnotation));\n            }\n\n            //this should be in a fixed or flow textcontainer\n            ITextContainer textContainer = textAnchor.Start.TextContainer;\n\n            Invariant.Assert(textContainer != null, \"TextAnchor does not belong to a TextContainer\");\n\n            if (attachedAnnotation.Annotation == null)\n            {\n                throw new ArgumentException(SR.AnnotationIsNull, nameof(attachedAnnotation));\n            }\n\n            //check annotation type\n            if (!_type.Equals(attachedAnnotation.Annotation.AnnotationType))\n            {\n                throw new ArgumentException(SR.Format(SR.NotHighlightAnnotationType, attachedAnnotation.Annotation.AnnotationType.ToString()), nameof(attachedAnnotation));\n            }\n\n            return textContainer;\n        }\n\n        /// <summary>\n        /// Converts a string to Color object\n        /// </summary>\n        /// <param name=\"color\">Color string</param>\n        /// <returns>Color object</returns>\n        private static Color GetColor(string color)\n        {\n            return (Color)ColorConverter.ConvertFromString(color);\n        }\n\n        /// <summary>\n        /// Gets the Colors from the Annotation's cargo. If corresponding Color is not present\n        /// a default value is used.","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/HighlightComponent.cs#L510-L546","documentation":"HighlightComponent.CheckInputData throws ArgumentException(SR.NotHighlightAnnotationType) when the annotation's AnnotationType does not equal the component's registered type (the WPF 'Highlight' type, http://schemas.microsoft.com/annotations/.../Highlight). Each IAnnotationComponent handles exactly one annotation type, so an annotation of another type (e.g. StickyNote) routed to HighlightComponent is rejected.","triggerScenarios":"Registering the same HighlightComponent for multiple annotation types via AnnotationService (actually AddHighlightComponent/its registration path) and then attaching an annotation whose type differs from the component's _type; attaching a 'Comment'/'StickyNote'-typed annotation to a highlight component.","commonSituations":"Custom annotation types defined with AnnotationType GUIDs/names that don't match; store round-trips that change the AnnotationType; copying annotations between services with different type mappings.","solutions":["Ensure the annotation's AnnotationType matches the Highlight type the component was created for (use AnnotationService.HighlightType-like constant rather than a custom string).","Create a custom IAnnotationComponent registered for your custom type instead of reusing HighlightComponent.","Log attachedAnnotation.Annotation.AnnotationType in your error handler to identify the mismatching type."],"exampleFix":"// before\nAnnotation a = new Annotation(new XmlQualifiedName(\"MyHighlight\", myNs));\nservice.EnableHighlight(a); // routed to HighlightComponent -> throws\n// after\nAnnotation a = new Annotation(AnnotationService.HighlightType);","handlingStrategy":"validation","validationCode":"if (attachedAnnotation?.Annotation != null && !component.ExpectedType.Equals(attachedAnnotation.Annotation.AnnotationType)) return; // type routed elsewhere","typeGuard":"static bool IsHighlightType(Annotation a) => a != null && a.AnnotationType.Equals(AnnotationService.HighlightType);","tryCatchPattern":"try { component.AddAttachedAnnotation(attachedAnnotation); } catch (ArgumentException ex) when (ex.Message.Contains(\"highlight\")) { /* route to matching component */ }","preventionTips":["Create annotations with the canonical Highlight AnnotationType","Route annotations to components by AnnotationType lookup, not fixed mapping","Persist and preserve AnnotationType on round-trips"],"tags":["wpf","annotations","argument-exception","annotation-type"],"backgroundTag":"invalid-enum-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"}