{"record":{"id":"d668a0767c248cca","repo":"dotnet/wpf","slug":"sr-invalidguid-annotation","errorCode":null,"errorMessage":"SR.InvalidGuid","messagePattern":"SR\\.InvalidGuid","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":136,"sourceCode":"        /// <exception cref=\"ArgumentNullException\">annotationType is null</exception>\n        /// <exception cref=\"ArgumentException\">lastModificationTime is earlier than creationTime</exception>\n        /// <exception cref=\"ArgumentException\">annotationType's Name or Namespace is null or empty string</exception>\n        /// <exception cref=\"ArgumentException\">id is equal to Guid.Empty</exception>\n        public Annotation(XmlQualifiedName annotationType, Guid id, DateTime creationTime, DateTime lastModificationTime)\n        {\n            ArgumentNullException.ThrowIfNull(annotationType);\n            if (String.IsNullOrEmpty(annotationType.Name))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Name\");//needs better message\n            }\n            if (String.IsNullOrEmpty(annotationType.Namespace))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Namespace\");//needs better message\n            }\n\n            if (id.Equals(Guid.Empty))\n            {\n                throw new ArgumentException(SR.InvalidGuid, nameof(id));\n            }\n            if (lastModificationTime.CompareTo(creationTime) < 0)\n            {\n                throw new ArgumentException(SR.ModificationEarlierThanCreation, nameof(lastModificationTime));\n            }\n            _id = id;\n            _typeName = annotationType;\n\n            _created = creationTime;\n            _modified = lastModificationTime;\n\n            Init();\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L118-L154","documentation":"Annotation's constructor rejects Guid.Empty as an annotation id, throwing ArgumentException with SR.InvalidGuid. Every Annotation requires a unique, non-empty Guid identifier used for persistence and lookup. Guid.Empty is treated as an uninitialized/invalid id rather than a valid value.","triggerScenarios":"Calling the public Annotation constructor (or the overload that accepts an id) passing Guid.Empty, typically because a Guid field was never initialized.","commonSituations":"Storing annotation ids in structs or fields that default to Guid.Empty; generating annotations before calling Guid.NewGuid(); reading ids from data sources that return zeroed Guids.","solutions":["Call Guid.NewGuid() to generate a fresh id for each new Annotation","Validate ids are not Guid.Empty before constructing the Annotation","If loading an existing annotation, ensure the persisted id was read correctly rather than defaulting"],"exampleFix":"// before\nvar ann = new Annotation(type, Guid.Empty, created, modified);\n// after\nGuid id = Guid.NewGuid();\nif (id == Guid.Empty) throw new InvalidOperationException(\"id must be generated\");\nvar ann = new Annotation(type, id, created, modified);","handlingStrategy":"validation","validationCode":"Guid id = Guid.NewGuid();\nif (id == Guid.Empty) throw new InvalidOperationException(\"Annotation id must not be Guid.Empty\");\nvar annotation = new Annotation(type, id, created, modified);","typeGuard":"bool IsValidAnnotationId(Guid id) => id != Guid.Empty;","tryCatchPattern":null,"preventionTips":["Never store Guid fields that can default to Guid.Empty for annotation ids; initialize with Guid.NewGuid()","When reading ids from persistence, verify they parse to a non-empty Guid","Add invariant checks in any factory method that wraps Annotation construction"],"tags":["wpf","annotations","guid"],"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-22T01:17:13.364Z"}