.NET 3.4.1 SDK Version: Certificate Parsing Issue on Linux: Invalid XML Signature and Schema Validation Errors

When using the .NET 8 SDK in a Windows environment, everything works as expected. However, when the same application is published and deployed to a Linux environment, an issue occurs during the signing and reporting of simplified XML invoices.

Error Message Returned by SDK:

[Error] Parsing EInvoice Certificate
[Error] Populating Signed Signature Properties

Root Cause:

After investigation, the issue seems to originate from the ParseCertificateMiddleware class. Specifically, the following code:

X509Certificate2 X509Certificate2 = new X509Certificate2(
    (byte[])(object)(from x in Encoding.UTF8.GetBytes(eInvoiceData.CertificateContent)
                     select (sbyte)x).ToArray());

This works on Windows but fails on Linux due to differences in how certificate content is handled. It appears that the certificate content is base64-encoded, and decoding it with Encoding.UTF8.GetBytes leads to an invalid byte array on Linux.

Suggested Fix:

Changing the code to use proper base64 decoding instead resolves the issue across both environments:

X509Certificate2 X509Certificate2 = new X509Certificate2(
    (byte[])(object)(from x in Convert.FromBase64String(eInvoiceData.CertificateContent)
                     select (sbyte)x).ToArray());

This approach correctly handles the certificate bytes and resolves the signing and validation issues when deployed on Linux.

Request:

Kindly review and consider updating the SDK to ensure platform-independent handling of certificates. This will help avoid deployment issues in Linux-based environments.

Dear @kyoussef

Thanks for reaching out, Welcome to our community.

without your changing, can you please elaborate more with the below:

1- What are the exact steps that you followed?
2- What is the SDK version that you are using?

Thanks,
Ibrahem Daoud.

Without this modification, the dlls that sign and encrypt the invoice have different additional files depending on the operating system type and are usually located in a folder :open_file_folder: runtime