{"record":{"id":"ba2a9e7feeae5abf","repo":"dotnet/wpf","slug":"sr-invalidguid-annotationresource","errorCode":null,"errorMessage":"SR.InvalidGuid","messagePattern":"SR\\.InvalidGuid","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs","lineNumber":76,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(name);\n\n            _name = name;\n            _id = Guid.NewGuid();\n        }\n\n        /// <summary>\n        ///     Creates an instance of Resource with the specified Guid as its Id.\n        ///     This constructor is for store implementations that use their own\n        ///     method of serialization and need a way to create a Resource with\n        ///     the correct read-only data.\n        /// </summary>\n        /// <param name=\"id\">the new Resource's id</param>\n        /// <exception cref=\"ArgumentException\">id is equal to Guid.Empty</exception>\n        public AnnotationResource(Guid id)\n        {\n            if (Guid.Empty.Equals(id))\n                throw new ArgumentException(SR.InvalidGuid, nameof(id));\n\n            // Guid is a struct and cannot be null\n            _id = id;\n        }\n\n        #endregion Constructors\n\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------\n\n        #region Public Methods\n        \n        #region IXmlSerializable Implementation\n\n        /// <summary>","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationResource.cs#L58-L94","documentation":"The AnnotationResource(Guid) constructor throws ArgumentException when the id parameter equals Guid.Empty. Every annotation resource must have a unique non-empty identifier; Guid.Empty is not a valid resource id per the annotations schema. The parameterless constructor generates a new Guid, so this only fires when a caller explicitly supplies an empty Guid.","triggerScenarios":"Constructing AnnotationResource with Guid.Empty, e.g. new AnnotationResource(Guid.Empty), often because a Guid field was default-initialized and never assigned.","commonSituations":"Deserializing metadata where the id was lost and default(Guid) was used; creating resources from data structures where Guid fields default to Guid.Empty; typo of passing an unset variable instead of a newly generated Guid.","solutions":["Use the parameterless AnnotationResource() constructor to auto-generate a valid Guid.","Generate a new id with Guid.NewGuid() before constructing the resource.","Ensure the Guid variable being passed is actually initialized; fix default(Guid) usage in your data model.","Validate ids after deserialization and regenerate empty ones."],"exampleFix":"// before\nvar resource = new AnnotationResource(Guid.Empty);\n\n// after\nvar resource = new AnnotationResource(Guid.NewGuid());","handlingStrategy":"validation","validationCode":"if (id == Guid.Empty)\n    id = Guid.NewGuid();\nvar resource = new AnnotationResource(id);","typeGuard":"bool IsValidResourceId(Guid id) => id != Guid.Empty;","tryCatchPattern":"try { resource = new AnnotationResource(id); }\ncatch (ArgumentException) { resource = new AnnotationResource(Guid.NewGuid()); }","preventionTips":["Prefer the parameterless AnnotationResource constructor.","Never persist default(Guid); validate ids after deserialization.","Use nullable Guid fields so 'unset' is distinguishable from a real id."],"tags":["wpf","annotations","guid","invalid-argument"],"backgroundTag":"invalid-identifier-format","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"}