XmlDSig Error: Did not find same-document Reference Id

If signing XML fails with the following message in the LastErrorText:

...
     Doing first SAX parse...
    checkAllReferencesFound:
      passNumber: 1
      reference:
        Did not find same-document Reference Id
        referenceId: id-1234567890
      --reference
    --checkAllReferencesFound
...

It means there was no XML element in the XML you were trying to sign that has an Id attribute with the given value.

For example, your source code might be trying to add a same-document reference like this:

    // -------- Reference 1 --------
    gen.AddSameDocRef("id-F9EFDBE6CD830436A2156958277490916","sha1","EXCL_C14N","oas soapenv v201 v202","");

    // -------- Reference 2 --------
    gen.AddSameDocRef("id-F9EFDBE6CD830436A2156958277490917","sha1","EXCL_C14N","oas v20 v201 v202","");

And the XML to be signed might look like this:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope ...>
    <soapenv:Header>
        <v20:kontekstWywolania oas:Id="id-F9EFDBE6CD830436A2156958277490916">
		...
		...
        </v20:kontekstWywolania>
    </soapenv:Header>
    <soapenv:Body oas:Id="id-F9EFDBE6CD830436A2156958277490917">
        <v201:ZapisDokumentuAnulowaniaReceptyRequest>
            <kluczRecepty>
                <v202:kluczRecepty>xyz</v202:kluczRecepty>
            </kluczRecepty>
            <dokumentAnulowaniaRecepty>
                <v202:tresc>xyz</v202:tresc>
            </dokumentAnulowaniaRecepty>
        </v201:ZapisDokumentuAnulowaniaReceptyRequest>
    </soapenv:Body>
</soapenv:Envelope>

Notice the Id attributes having the values that match the Id’s passed in the 1st argument to AddSameDocRef.
If the Id passed in AddSameDocRef is not found in the XML, then you’ll get the error “Did not find same-document Reference Id”

Tags :