{"record":{"id":"292c24a76ad9f929","repo":"dotnet/wpf","slug":"object-identifiers-must-be-unique-within-the-same-signature","errorCode":null,"errorMessage":"Object identifiers must be unique within the same signature.","messagePattern":"Object identifiers must be unique within the same signature\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":964,"sourceCode":"            // Check for empty collections in order to provide negative feedback as soon as possible.\n            if (EnumeratorEmptyCheck(parts) && EnumeratorEmptyCheck(relationshipSelectors)\n                && EnumeratorEmptyCheck(signatureObjects) && EnumeratorEmptyCheck(objectReferences))\n                throw new ArgumentException(SR.NothingToSign);\n\n            // check for illegal and/or duplicate id's in signatureObjects\n            if (signatureObjects != null)\n            {\n                List<String> ids = new List<String>();\n                foreach (DataObject obj in signatureObjects)\n                {\n                    // ensure they don't duplicate the reserved one\n                    if (string.Equals(obj.Id, XTable.Get(XTable.ID.OpcAttrValue), StringComparison.Ordinal))\n                        throw new ArgumentException(SR.SignaturePackageObjectTagMustBeUnique, nameof(signatureObjects));\n\n                    // check for duplicates\n                    //if (ids.Contains(obj.Id))\n                    if (ids.Exists(new StringMatchPredicate(obj.Id).Match))\n                        throw new ArgumentException(SR.SignatureObjectIdMustBeUnique, nameof(signatureObjects));\n                    else\n                        ids.Add(obj.Id);\n                }\n            }\n\n            // ensure id is legal Xml id\n            if (!string.IsNullOrEmpty(signatureId))\n            {\n                try\n                {\n                    // An XSD ID is an NCName that is unique.\n                    System.Xml.XmlConvert.VerifyNCName(signatureId);\n                }\n                catch (System.Xml.XmlException xmlException)\n                {\n                    throw new ArgumentException(SR.Format(SR.NotAValidXmlIdString, signatureId), nameof(signatureId), xmlException);\n                }\n            }","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L946-L982","documentation":"VerifySignArguments enforces that DataObject Ids are unique within the signature: a duplicate Id throws ArgumentException (SR.SignatureObjectIdMustBeUnique) for the signatureObjects parameter. XML-DSig requires object IDs to be unique XML IDs within one signature document.","triggerScenarios":"Calling Sign() with two or more DataObjects sharing the same Id string in the signatureObjects collection.","commonSituations":"Adding the same DataObject instance twice, or generating objects in a loop with a fixed/constant Id rather than a counter.","solutions":["Give each DataObject a distinct Id (e.g. suffix with an index: obj1, obj2, ...).","Deduplicate the signatureObjects collection before calling Sign (e.g. DistinctBy(o => o.Id)).","Pre-validate uniqueness with a HashSet of Ids before invoking Sign."],"exampleFix":"// before\nobjs.Add(new DataObject { Id = \"obj1\", ObjectXml = xmlA });\nobjs.Add(new DataObject { Id = \"obj1\", ObjectXml = xmlB }); // duplicate\n// after\nobjs.Add(new DataObject { Id = \"obj1\", ObjectXml = xmlA });\nobjs.Add(new DataObject { Id = \"obj2\", ObjectXml = xmlB });","handlingStrategy":"validation","validationCode":"var ids = new HashSet<string>(StringComparer.Ordinal);\nforeach (var o in sigObjects ?? Enumerable.Empty<DataObject>())\n    if (!ids.Add(o.Id)) throw new InvalidOperationException($\"Duplicate DataObject Id: {o.Id}\");","typeGuard":null,"tryCatchPattern":"try { mgr.Sign(cert, parts, null, sigObjects, null); }\ncatch (ArgumentException ex) when (ex.ParamName == \"signatureObjects\") { /* dedupe ids and retry */ }","preventionTips":["Generate unique ids per DataObject (index or GUID suffix).","Deduplicate the collection before signing.","Avoid constant id strings inside loops."],"tags":["wpf","packaging","argument","duplicate-identifier","digital-signature"],"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"}