after more than 100 tries sdk 3.3.3 is working 3.3.5 not working stil there is problem here is the steps to do it
first download zatca-einvoicing-sdk-238-R3.3.3
first add refrence
using System;
using System.Xml;
copy all files from this folder to your project in bin folder
C:\test2\zatca-einvoicing-sdk-238-R3.3.3\zatca-einvoicing-sdk-238-R3.3.3\zatca-einvoicing-sdk-238-R3.3.3\Lib.Net\Test
copy all files from this folder to your project in bin folder and replace the file
C:\test2\zatca-einvoicing-sdk-238-R3.3.3\zatca-einvoicing-sdk-238-R3.3.3\zatca-einvoicing-sdk-238-R3.3.3\Lib.Net\DLL\Zatca.EInvoice.SDK\net4
add refrence to this dll filees
Zatca.EInvoice.SDK.dll
Zatca.EInvoice.SDK.Contracts.dll
this is the code
using System;
using System.Xml;
using Zatca.EInvoice.SDK.Contracts.Models;
using Zatca.EInvoice.SDK;
using System.Linq;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
String privateKey = "MHQCAQEEIL14JV+5nr/sE8Sppaf2IySovrhVBtt8+yz+g4NRKyz8oAcGBSuBBAAKoUQDQgAEoWCKa0Sa9FIErTOv0uAkC1VIKXxU9nPpx2vlf4yhMejy8c02XJblDq7tPydo8mq0ahOMmNo8gwni7Xt1KT9UeA==";
string certificateContent = "MIID3jCCA4SgAwIBAgITEQAAOAPF90Ajs/xcXwABAAA4AzAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQUlpFSU5WT0lDRVNDQTQtQ0EwHhcNMjQwMTExMDkxOTMwWhcNMjkwMTA5MDkxOTMwWjB1MQswCQYDVQQGEwJTQTEmMCQGA1UEChMdTWF4aW11bSBTcGVlZCBUZWNoIFN1cHBseSBMVEQxFjAUBgNVBAsTDVJpeWFkaCBCcmFuY2gxJjAkBgNVBAMTHVRTVC04ODY0MzExNDUtMzk5OTk5OTk5OTAwMDAzMFYwE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iYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==";
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.Load(XMLPath);
SignResult signResult = new EInvoiceSigner().SignDocument(doc, certificateContent, privateKey);
if (signResult != null && signResult.IsValid)
{
signResult.SaveSignedEInvoice(XMLPathSignedPAth);
string resultedValue = signResult.Steps.Where<StepResult>((Func<StepResult, bool>)(s => s.StepName.Contains("Generate EInvoice Hash"))).First<StepResult>().ResultedValue;
Console.WriteLine("Invoice signed successfully");
Console.WriteLine("The Invoice Hash = " + resultedValue);
Console.WriteLine("Validating invoice");
XmlDocument doc2 = new XmlDocument();
doc2.PreserveWhitespace = true;
doc2.Load(XMLPathSignedPAth);
ValidationResult validationResult = new EInvoiceValidator().ValidateEInvoice(doc2, certificateContent, PIH );
if (validationResult.IsValid)
{ Console.WriteLine("Valied"); }
else { Console.WriteLine("Not Valied"); }
Console.ReadLine();
}
}
}
}