# .NET SDK Signing not working in ASP API server, but working fine in ASP.Net web form

**URL:** <https://zatca1.discourse.group/t/net-sdk-signing-not-working-in-asp-api-server-but-working-fine-in-asp-net-web-form/6050>\
**Category:** SDK, web-based validator and sandbox\
**Created:** [February 25, 2025, 1:47pm UTC](https://zatca1.discourse.group/t/net-sdk-signing-not-working-in-asp-api-server-but-working-fine-in-asp-net-web-form/6050 "2025-02-25T13:47:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![faheemmcfc](https://avatars.discourse-cdn.com/v4/letter/f/ed655f/32.png) [@faheemmcfc](https://zatca1.discourse.group/u/faheemmcfc)\
**Post date:** [February 25, 2025, 1:47pm UTC](https://zatca1.discourse.group/t/net-sdk-signing-not-working-in-asp-api-server-but-working-fine-in-asp-net-web-form/6050/1 "2025-02-25T13:47:58Z")

</div>

I successfully built an [ASP.NET](http://ASP.NET) application which uses Zatca .NET SDK (Saudi Arabia E-Invoicing) to create and sign xml files. Everything is working fine in [ASP.NET](http://ASP.NET) with the SDK.

Now I am trying to make a .NET API to do the same functions. But when executing the API, it gets stuck in a function. Where the function is using Zatca .NET SDK to execute.

Code of the function is:

```auto
public static string[] SignDocument(XmlDocument doc, string signedPath, string certificate, string privateKey)
{
        string[] retresult = new string[3];

        try
        {
            SignResult result = new EInvoiceSigner().SignDocument(doc, certificate, privateKey);

            if (result != null && result.IsValid)
            {
                result.SaveSignedEInvoice(signedPath);
                string hash = (from s in result.Steps
                               where s.StepName.Contains("Generate EInvoice Hash")
                               select s).First<StepResult>().ResultedValue;

                string[] RequestResult = new string[2];
                RequestResult = GenerateRequest(signedPath);

                if (RequestResult[0] == "success")
                {
                    retresult[0] = "success";
                    retresult[1] = hash;
                    retresult[2] = RequestResult[1];
                    return retresult;
                }
                else
                {
                    retresult[0] = "invreq";
                    retresult[1] = "";
                    retresult[2] = "";
                    return retresult;
                }
            }
            else
            {
                retresult[0] = "sign";
                return retresult;
            }
        }
        catch (Exception ex)
        {
            retresult[0] = "failed";
            return retresult;
        }
}

```

Here on executing the below line it shows QR code error.

```auto
SignResult result = new EInvoiceSigner().SignDocument(doc, certificate, privateKey);

```

The error is passed from the SDK. Problem is that the same function is working fine in the [ASP.NET](http://ASP.NET) application. Everything is the same. Using same SDK dll, same values are passed to the function.

I tried different checking and couldn’t find any success. I also tried to extract code from the SDK dll and it’s as below:

```auto
namespace Zatca.EInvoice.SDK
{
  public class EInvoiceSigner : IEInvoiceSigner
  {
    private readonly CoRExecutor signDocumentExecutor;

    public EInvoiceSigner()
    {
      this.signDocumentExecutor = new CoRExecutor().AddMiddleware<ValidateSignInputsMiddleware>().AddMiddleware<GenerateHashMiddleware>().AddMiddleware<GenerateSignatureMiddleware>().AddMiddleware<ParseCertificateMiddleware>().AddMiddleware<HashCertificatesMiddleware>().AddMiddleware<TransformXMLResultMiddleware>().AddMiddleware<PopulateSignedSignaturePropertiesMiddleware>().AddMiddleware<PopulateUBLExtensionsMiddleware>().AddMiddleware<GenerateQRMiddleware>().AddMiddleware<FinalizeSignDocumentMiddleware>();
    }

    public SignResult SignDocument(
      XmlDocument eInvoice,
      string certificateContent,
      string privateKeyContent)
    {
      EInvoiceData invoice = new EInvoiceData(eInvoice)
      {
        CertificateContent = certificateContent,
        PrivateKeyContent = privateKeyContent
      };
      this.signDocumentExecutor.Execute(invoice);
      return new SignResult()
      {
        SignedEInvoice = invoice.EInvoice,
        IsValid = invoice.IsValid,
        ErrorMessage = invoice.Errors,
        Steps = invoice.Steps
      };
    }
  }
}

```

Error shown is:

> [Error] Generating EInvoice Signature[Error] Generating EInvoice QR Code

I can not make any changes to the SDK. I can not understand the problem. Please help
