{"record":{"id":"7f1972c368fb604c","repo":"dotnet/wpf","slug":"extendedproperty-is-already-part-of-the","errorCode":null,"errorMessage":"ExtendedProperty is already part of the ExtendedPropertyCollection.","messagePattern":"ExtendedProperty is already part of the ExtendedPropertyCollection\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/ExtendedPropertyCollection.cs","lineNumber":150,"sourceCode":"        {\n            ExtendedPropertyCollection copied = new ExtendedPropertyCollection();\n            for (int x = 0; x < _extendedProperties.Count; x++)\n            {\n                copied.Add(_extendedProperties[x].Clone());\n            }\n            return copied;\n        }\n\n        /// <summary>\n        /// Add\n        /// </summary>\n        /// <param name=\"id\">Id</param>\n        /// <param name=\"value\">value</param>\n        internal void Add(Guid id, object value)\n        {\n            if (this.Contains(id))\n            {\n                throw new ArgumentException(SR.EPExists, nameof(id));\n            }\n\n            ExtendedProperty extendedProperty = new ExtendedProperty(id, value);\n\n            //this will raise change events\n            this.Add(extendedProperty);\n        }\n\n\n        /// <summary>\n        /// Remove\n        /// </summary>\n        /// <param name=\"id\">id</param>\n        internal void Remove(Guid id)\n        {\n            if (!Contains(id))\n            {\n                throw new ArgumentException(SR.EPGuidNotFound, nameof(id));","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/ExtendedPropertyCollection.cs#L132-L168","documentation":"ExtendedPropertyCollection.Add(Guid, object) first checks Contains(id) and throws ArgumentException(SR.EPExists, nameof(id)) — 'ExtendedProperty is already part of the ExtendedPropertyCollection.' — when a property with the same GUID already exists. The collection requires unique keys; duplicates must go through the indexer's set accessor instead.","triggerScenarios":"Calling Add(guid, value) twice with the same GUID; decoding ISF (DecodeRawISF) whose payload lists the same property id more than once for one object.","commonSituations":"Applying default properties on ink objects that already have them; replaying/importing ISF data with duplicated property tags (double-applied transforms or merges); re-running an import routine without clearing the collection.","solutions":["Use the indexer (collection[guid] = value) to overwrite an existing property instead of Add.","Check Contains(guid) before Add and skip, overwrite, or remove-then-add as appropriate.","Deduplicate property lists before decoding/persisting ISF so the same id isn't added twice.","Catch ArgumentException with the 'id' param name to handle duplicates from external data gracefully."],"exampleFix":"// before\nproperties.Add(guid, value); // ArgumentException if guid already present\n// after\nif (properties.Contains(guid))\n    properties[guid] = value;\nelse\n    properties.Add(guid, value);","handlingStrategy":"validation","validationCode":"if (properties.Contains(id))\n    properties[id] = value;\nelse\n    properties.Add(id, value);","typeGuard":"static bool IsNewProperty(ExtendedPropertyCollection c, Guid id) => !c.Contains(id);","tryCatchPattern":"try { properties.Add(id, value); }\ncatch (ArgumentException ex) when (ex.ParamName == \"id\") { properties[id] = value; /* upsert */ }","preventionTips":["Prefer the indexer for set-or-overwrite semantics","Deduplicate ids when importing ISF","Clear or diff collections before re-running imports"],"tags":["wpf","ink","extendedpropertycollection","duplicate-key","argumentexception"],"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"}