# .NET SDK Private Key Error but successfully signing through CLI

**URL:** <https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047>\
**Category:** SDK, web-based validator and sandbox\
**Created:** [September 16, 2024, 9:23am UTC](https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047 "2024-09-16T09:23:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tufail129](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tufail129](https://zatca1.discourse.group/u/tufail129)\
**Post date:** [September 16, 2024, 9:23am UTC](https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047/1 "2024-09-16T09:23:25Z")

</div>

We are encountering an issue with the SDK when signing an XML file. Using the .net **SDK ( v3.3.5)** , the XML is signed and **validated successfully through simulation CLI**. However, when we attempt to sign the same XML using the C# SDK with .NET 4.8, we encounter the following error when we invoke the function “**signer.SignDocument(xmlDoc, certificate, privateKey);**”:  
**im using the private key which is generated along with CSR. and i copy paste in the destination “ec-secp256k1-priv-key.pem” accordingly mentioned in guidelines.**

_Problem creating EC private key: System.NullReferenceException: Object reference not set to an instance of an object._

_at Org.BouncyCastle.Security.PrivateKeyFactory.CreateKey(PrivateKeyInfo keyInfo) in /\_/crypto/src/security/PrivateKeyFactory.cs:line 110_

_at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject) in /\_/crypto/src/openssl/PEMReader.cs:line 321_

**code :**

 ![image (1)](https://europe1.discourse-cdn.com/flex013/uploads/zatca1/original/1X/6e0cc70875e5ecf1c870dacd7e1c70cac4cf022e.png)

Could you please provide assistance or guidance on how to resolve this issue?

We appreciate your support and look forward to your response.

---

<div class="post-metadata">

**Author:** ![CDAdeveloper](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@CDAdeveloper](https://zatca1.discourse.group/u/CDAdeveloper)\
**Post date:** [October 7, 2024, 9:08am UTC](https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047/3 "2024-10-07T09:08:57Z")

</div>

Hello, I have the same problem  
Is there any solution??  
help me,  
Thanks,

---

<div class="post-metadata">

**Author:** ![Akbersha\_20](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Akbersha\_20](https://zatca1.discourse.group/u/Akbersha_20)\
**Post date:** [July 22, 2025, 10:27am UTC](https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047/4 "2025-07-22T10:27:10Z")

</div>

I’m also facing the same issue… problem creating EC private key: System.ArgumentException: failed to construct sequence from byte: unknown tag 13 encountered\r\n at Org.BouncyCastle.Asn1.Asn1Sequence.GetInstance(Object obj) in /_/crypto/src/asn1/Asn1Sequence.cs:line 41\r\n at Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject) in /_/crypto/src/openssl/PEMReader.cs:line 271

---

<div class="post-metadata">

**Author:** ![Akbersha\_20](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Akbersha\_20](https://zatca1.discourse.group/u/Akbersha_20)\
**Post date:** [July 22, 2025, 12:06pm UTC](https://zatca1.discourse.group/t/net-sdk-private-key-error-but-successfully-signing-through-cli/3047/5 "2025-07-22T12:06:16Z")

</div>

@tufail129 , did you get any solution for this ?
