XmlDSig Error: "Did not find same-document Reference Id"

The Chilkat error message

XmlDSig Error: "Did not find same-document Reference Id"

means that during XML Digital Signature verification or creation, Chilkat could not find the element within the same XML document that corresponds to the Reference element’s URI (usually an internal fragment identifier, like #id123).


What It Means

In XMLDSig, each <Reference> in <SignedInfo> specifies what part of the document is being signed. For example:

<Reference URI="#invoice123">
   <Transforms>...</Transforms>
   <DigestMethod Algorithm="..."/>
   <DigestValue>...</DigestValue>
</Reference>

Chilkat then looks for an element in the same XML document with:

<SomeElement Id="invoice123"> ... </SomeElement>

If it can’t find that element — i.e., there’s no element with a matching Id, ID, or xml:id attribute — it throws:

"Did not find same-document Reference Id"


Common Causes

  1. The referenced Id attribute is missing.
    • Example: <Invoice> exists, but doesn’t have Id="invoice123".
  2. The attribute name doesn’t match exactly.
    • Chilkat recognizes Id, ID, or xml:id as valid XML ID attributes.
    • But if your element uses id="..." (lowercase) and your XML doesn’t declare it as type ID, Chilkat won’t find it.
  3. The Reference URI is empty or malformed.
    • URI="" means the entire document is signed.
    • If the URI starts with #, Chilkat expects a same-document element with a matching ID.
  4. Namespaces or canonicalization altered the attribute.
    • If the XML was transformed (e.g., enveloped signature), the Id might have been stripped or moved.