{"record":{"id":"01f176ce32913281","repo":"dotnet/wpf","slug":"sr-annotationisnull","errorCode":null,"errorMessage":"SR.AnnotationIsNull","messagePattern":"SR\\.AnnotationIsNull","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/HighlightComponent.cs","lineNumber":522,"sourceCode":"        /// <returns>The AttachedAnchor TextContainer</returns>\n        private ITextContainer CheckInputData(IAttachedAnnotation attachedAnnotation)\n        {\n            ArgumentNullException.ThrowIfNull(attachedAnnotation);\n\n            TextAnchor textAnchor = attachedAnnotation.AttachedAnchor as TextAnchor;\n            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        {","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Component/HighlightComponent.cs#L504-L540","documentation":"HighlightComponent.CheckInputData throws ArgumentException(SR.AnnotationIsNull) when the attached annotation wrapper carries a null Annotation object even though the anchor itself was a valid TextAnchor. The component needs the actual Annotation instance to compare its AnnotationType and read its resource payload (colors), so a null annotation cannot be processed.","triggerScenarios":"AddAttachedAnnotation invoked with an IAttachedAnnotation implementation whose Annotation property returns null; hand-rolled IAttachedAnnotation implementations that forget to set Annotation.","commonSituations":"Custom annotation loaders that populate AttachedAnchor but not Annotation; deserialization failures that silently leave the Annotation null; unit-test stubs missing property setup.","solutions":["Ensure the IAttachedAnnotation passed to AddAttachedAnnotation has a non-null Annotation property.","If loading annotations from a store, verify the load succeeded (Annotation not null) before attaching to the component.","Fix custom IAttachedAnnotation implementations to always set Annotation in the constructor."],"exampleFix":"// before\nattachedAnnotation = new AttachedAnnotation(anchor, null, level);\n// after\nif (annotation == null) throw new ArgumentNullException(nameof(annotation));\nattachedAnnotation = new AttachedAnnotation(anchor, annotation, level);","handlingStrategy":"validation","validationCode":"if (attachedAnnotation?.Annotation == null) return; // do not attach","typeGuard":"static bool HasAnnotation(IAttachedAnnotation a) => a?.Annotation != null;","tryCatchPattern":"try { component.AddAttachedAnnotation(attachedAnnotation); } catch (ArgumentException ex) when (ex.ParamName == nameof(attachedAnnotation)) { log.Warn(\"null annotation\"); }","preventionTips":["Validate store load results before attaching","Enforce non-null Annotation in custom wrapper constructors","Avoid swallowing deserialization errors that leave Annotation null"],"tags":["wpf","annotations","null-argument","argument-exception"],"backgroundTag":"null-argument","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"}