dotnet/wpf · error · XmlException
SR.SignatureObjectIdMustBeUnique
Error message
SR.SignatureObjectIdMustBeUnique
What it means
GetPackageDataObject scans the signature's ObjectList for the DataObject whose Id is the OPC package object id. Two DataObjects with the same Id make the selection ambiguous, so XmlException(SR.SignatureObjectIdMustBeUnique) is thrown: per XML DSig, Object element Id attributes must be unique within a signature.
Solutions
- Re-sign the package with PackageDigitalSignatureManager.Sign so a single, unique package Object is generated.
- If adding custom Objects, assign each a distinct Id attribute different from the OPC package object Id.
- Inspect the signature XML and remove the duplicate <Object> element with the reserved Id.
- Treat the signature as corrupt and remove it (dsm.RemoveSignature(sig)) if it cannot be repaired.
Example fix
// before: duplicate Ids <Object Id="idPackageObject">...</Object> <Object Id="idPackageObject">...</Object> // after: unique Ids <Object Id="idPackageObject">...</Object> <Object Id="myCustomObject">...</Object>
Defensive patterns
Strategy: validation
Validate before calling
var ids = doc.SelectNodes("//*[local-name()='Object']/@Id")
.Cast<XmlAttribute>().Select(a => a.Value).ToList();
bool unique = ids.Count == ids.Distinct().Count(); Type guard
static bool ObjectIdsUnique(XmlDocument doc) =>
doc.SelectNodes("//*[local-name()='Object']/@Id").Cast<XmlAttribute>()
.GroupBy(a => a.Value).All(g => g.Count() == 1); Try / catch
try { dsm.VerifySignatures(true); }
catch (XmlException ex) { /* duplicate Object Id — remove and re-sign */ } Prevention
- Give every custom Object element a unique Id.
- Never append Objects with the OPC-reserved package object Id.
- Detect duplicates by scanning Id attributes before verification.
- Re-sign to regenerate a clean ObjectList.
When it happens
Trigger: Verify or property access on a PackageSignature whose SignedXml Signature.ObjectList contains two or more <Object> elements sharing the package object Id (the OPC-reserved id), e.g. after custom code appended a second Object with the same Id.
Common situations: Custom signing code that adds its own Object without changing the Id; repeated application of a signing step that appends instead of replaces; merging signatures from two documents.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.DuplicateObjectId
- SR.MultipleRelationshipTransformsFound
- SR.PackageSignatureObjectTagRequired
- SR.PackageSpecificReferenceTagMustBeUnique
- SR.RequiredXmlAttributeMissing (uri)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/08a2ddb2a4861f93.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlDigitalSignatureProcessor.cs:1049
/// <summary>
/// Finds and return the package-specific Object tag
/// </summary>
/// <returns></returns>
private DataObject GetPackageDataObject()
{
EnsureXmlSignatureParsed();
// look for the Package-specific object tag
String opcId = XTable.Get(XTable.ID.OpcAttrValue);
DataObject returnValue = null;
foreach (DataObject dataObject in _signedXml.Signature.ObjectList)
{
if (string.Equals(dataObject.Id, opcId, StringComparison.Ordinal))
{
// duplicates not allowed
if (returnValue != null)
throw new XmlException(SR.SignatureObjectIdMustBeUnique);
returnValue = dataObject;
}
}
// Package object tag required
if (returnValue != null)
return returnValue;
else
throw new XmlException(SR.PackageSignatureObjectTagRequired);
}
private KeyInfo GenerateKeyInfo(AsymmetricAlgorithm key, X509Certificate2 signer)
{
// KeyInfo section
KeyInfo keyInfo = new KeyInfo();
KeyInfoName keyInfoName = new KeyInfoName
{View on GitHub (pinned to 81131a70a4)