Why dll in zatca-einvoicing-sdk-238-R3.3.4 dll not sign correctly

any one know what is the problem with dll
when i sign with cmd fatooraNet sign -invoice c:\test\bassam.xml -signedInvoice c:\test\bas.xml
the file pass

when i sign the same xml with dll in code
SignResult result = signer.SignDocument(doc, certificateContent, privateKey);
the file not pass

the same certificate i use and private key and with dll not working

1 Like

Yes, that’s the problem with .Net SDK library. Many questions about this, and so far there has been no enlightenment from the Zatca Team.

Overall Sign Result: Valid

Step: Validate Sign Inputs
  Status: Valid
Step: Generate EInvoice Hash
  Status: Valid
Step: Generate Signature
  Status: Valid
Step: Parse Certificate
  Status: Valid
Step: Hash Certificate
  Status: Valid
Step: Transform Xml Result
  Status: Valid
Step: Populate Signed Signature Properties
  Status: Valid
Step: Populate UBL Extensions
  Status: Valid
Step: Generate EInvoice QR
  Status: Valid
Step: Finalize Sign Document
  Status: Valid

Overall validation Result: Invalid

Step: Initialization Step (Simplified EInvoice)
  Status: Valid
Step: Validate XSD
  Status: Valid
Step: Validate EN Schematrons
  Status: Invalid
  Errors:
    - [Error] occurred in validating Schematrons.
Step: Validate KSA Schematrons
  Status: Invalid
  Errors:
    - [Error] occurred in validating Schematrons.
Step: Generate EInvoice Hash
  Status: Valid
Step: Parse Certificate
  Status: Valid
Step: Generate EInvoice QR
  Status: Valid
Step: Validate QR Code
  Status: Invalid
  Errors:
    - [Error] CODE: hashedXml, MESSAGE: hashedXml does not match with qr code hashedXml or the hashedXml is missing
Step: Validate EInvoice Signature
  Status: Invalid
  Errors:
    - [Error] CODE: invoiceSignedDataDigestValue, MESSAGE: wrong invoice hashing.
    - [Error] CODE: signatureValue, MESSAGE: Wrong signature value.
    - [Error] CODE: xadesSignedPropertiesDigestValue, MESSAGE: wrong xadesSignedPropertiesDigestValue
Step: Validate EInvoice PIH
  Status: Valid

I think there is a bug in signing process from dll, There error related to the tag <?xml version="1.0" encoding="UTF-8"?> in first line in the signed xml doc;
All of us pass xml documnet without header <?xml version="1.0" encoding="UTF-8"?> to the sign method, but the result signed xml document has this tag in the first line

@hadarasoft

From my test, now error or bug on signing process, all step work well, Signed Document Accepted by Compliance Invoice Check, Reporting or Clearance with no any errors or warnings.

The Issue in .Net library is how to use this library to validate Signed Invoice.

good news, but do you check your signed xml in sandbox

what is the result?

Note, this TestXML page can only be used to test Invoices signed using Certificates and Private keys contained in the SDK, this will result in an error if your invoice is signed using another certificate and private key.

The best way is to test invoice directly to the Compliance Check Invoice API or Reporting Api / Clearance Api.

This is my result test of .NET8 library from Zatca.eInvoice.SDK

I. ONBOARDING PROCESS

Step 1
CSR and PrivateKey Generated Successfully
Step 2
GET CCSID Successfully
Step 3
Send Sample Invoice Successfully
Step 4
Get PCSID Successfully
Data has been serialized to the file.


II. APPROVAL PROCESS

1. Get Standard Invoice Approval

Clearance Standard Invoice
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "clearanceStatus": "CLEARED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  },
  "clearedInvoice": ".........."
}


Clearance Standard Credit Note
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "clearanceStatus": "CLEARED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  },
  "clearedInvoice": ".........."
}


Clearance Standard Debit Note
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "clearanceStatus": "CLEARED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  },
  "clearedInvoice": ".........."
}



1. Get Simplified Invoice Approval


Reporting Simplified Invoice
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "reportingStatus": "REPORTED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  }
}


Reporting Simplified Credit Note
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "reportingStatus": "REPORTED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  }
}


Reporting Simplified Debit Note
{
  "requestType": "Invoice Reporting",
  "requestUrl": "https://gw-fatoora.zatca.gov.sa/e-invoicing/developer-portal/compliance/invoices",
  "statusCode": "200-OK",
  "reportingStatus": "REPORTED",
  "validationResults": {
    "status": "PASS",
    "infoMessages": [
      {
        "status": "PASS",
        "type": "INFO",
        "code": "XSD_ZATCA_VALID",
        "category": "XSD validation",
        "message": "Complied with UBL 2.1 standards in line with ZATCA specifications"
      }
    ],
    "warningMessages": [],
    "errorMessages": []
  }
}




ALL DONE!



C:\Users\Incredible One\source\repos\ZatcaWithSDK\ZatcaWithSDK\bin\Debug\net8.0\ZatcaWithSDK.exe (process 11512) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

I followed the previous steps and I get Signed Invoice correctly, but when I call:
new EInvoiceValidator().ValidateEInvoice(xml, certificateContent, pihContent)
I get errors in validating:

  1. Validate EN Schematrons => [Error] occurred in validating Schematrons.
  2. Validate KSA Schematrons => [Error] occurred in validating Schematrons.
    Note that ValidateEInvoice() is not used in sample project on Github Repository

@Muhammed

Yes, that’s what I’m waiting for in this forum, I hope someone can provide a guide or example, how to use Invoice Validation…

@Ankit_Tiwari Please help we want to use ValidateEnvoice
when use it
we get this error :

  1. Validate EN Schematrons => [Error] occurred in validating Schematrons.
  2. Validate KSA Schematrons => [Error] occurred in validating Schematrons.
1 Like

after more than tri there is the solution

if you use Dotnet SDK DLL include in your Project
Use this code when Load XML file or string to XmlDocument before signe by signing funtion

XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml(xmlInvoice);

have overcome on this error?

@bhattiasadlatif
Look at the SDK Release history, if your invoice is not affected by the fixes added in each release, you can use version 3.3.3.

Or use the latest version (3.3.6 for now) and skip or leave Validation.

Until the developer or admin provides an explanation about this problem