dotnet/wpf · error · XmlException
SR.DuplicateObjectId
Error message
SR.DuplicateObjectId
What it means
CustomSignedXml.SelectNodeByIdFromEnemies/FromObjects resolves a reference ID by scanning SignedXml Object elements. If two Objects carry the same Id matching the requested value, the document is ambiguous and an XmlException (SR.DuplicateObjectId) is thrown rather than silently picking one.
Solutions
- Fix the signature generator so each <Object> has a unique Id.
- Remove or rename duplicate Object elements before verification.
- Catch XmlException during verification and reject the signature as invalid.
- Validate signature XML for duplicate IDs with an XML schema/ID uniqueness check before processing.
Example fix
// before: verifying a signature that may contain duplicate Object Ids
bool ok = signedXml.CheckSignature();
// after
try { bool ok = signedXml.CheckSignature(); }
catch (XmlException)
{ rejectSignature("Duplicate Object Id in signature"); } Defensive patterns
Strategy: validation
Validate before calling
// pre-check uniqueness of Object Ids in the signature XML before verification
var ids = sigDoc.SelectNodes("//*[local-name()='Object' and @Id]")
.Cast<XmlNode>().Select(n => n.Attributes["Id"].Value);
if (ids.GroupBy(x => x, StringComparer.Ordinal).Any(g => g.Count() > 1))
throw new InvalidDataException("Signature contains duplicate Object Ids"); Type guard
bool HasUniqueObjectIds(XmlDocument doc) =>
doc.SelectNodes("//*[local-name()='Object' and @Id]")
.Cast<XmlNode>().Select(n => n.Attributes["Id"].Value)
.GroupBy(x => x, StringComparer.Ordinal).All(g => g.Count() == 1); Try / catch
try { bool ok = customSignedXml.CheckSignature(); }
catch (XmlException e) { RejectSignature($"Malformed or ambiguous signature: {e.Message}"); } Prevention
- Ensure signature generators assign unique Object Ids
- Validate ID uniqueness before verification (defends against signature-wrapping tricks)
- Treat duplicate-ID signatures as invalid, never resolve them heuristically
When it happens
Trigger: Calling GetIdElement on a CustomSignedXml whose signature contains two or more <Object Id="same-id"> elements, typically during signature verification of a crafted or badly generated signature.
Common situations: XML signatures produced by buggy generators that reuse Object IDs; maliciously crafted signatures attempting reference ambiguity (signature wrapping); manual merging of signature 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.SignatureObjectIdMustBeUnique
- Resource_XpsPackageBoundaryViolation
- Resource_XpsPackageBoundaryViolation
- SR.FailToLaunchDefaultBrowser
- SR.Format(SR.BamlIsNotSupportedOutsideOfApplicationResources…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/481e7b0501586efd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CustomSignedXml.cs:80
/// Locate and return the node identified by idValue
/// </summary>
/// <param name="signature"></param>
/// <param name="idValue"></param>
/// <returns>node if found - else null</returns>
/// <remarks>Tries to match each object in the Object list.</remarks>
private static XmlElement SelectNodeByIdFromObjects(Signature signature, string idValue)
{
XmlElement node = null;
// enumerate the objects
foreach (DataObject dataObject in signature.ObjectList)
{
// direct reference to Object id - supported for all reference typs
if (string.Equals(idValue, dataObject.Id, StringComparison.Ordinal))
{
// anticipate duplicate ID's and throw if any found
if (node != null)
throw new XmlException(SR.DuplicateObjectId);
node = dataObject.GetXml();
}
}
// now search for XAdES specific references
if (node == null)
{
// For XAdES we implement special case where the reference may
// be to an internal tag with matching "Id" attribute.
node = SelectSubObjectNodeForXAdES(signature, idValue);
}
return node;
}
/// <summary>
/// Locate any signed Object tag that matches the XAdES "target type"View on GitHub (pinned to 81131a70a4)