none
signedXml.ComputeSignature() throws "OutOfMemory" exception RRS feed

  • Question

  • Hello All,

    When i try to sign large xml file(File Size : 253 Mb) ComputeSignature() throws "OutOfMemory" exception.

    I have x64 architecture system and i am using .Net framework 4.5.1

    my signing code is below.

    public static void SignXml(XmlDocument xmlDoc, RSA Key)
            {
                // Check arguments.
                if (xmlDoc == null)
                    throw new ArgumentException("xmlDoc");
                if (Key == null)
                    throw new ArgumentException("Key");

                // Create a SignedXml object.
                SignedXml signedXml = new SignedXml(xmlDoc);

                // Add the key to the SignedXml document.
                signedXml.SigningKey = Key;

                // Create a reference to be signed.
                Reference reference = new Reference();
                reference.Uri = "";

                // Add an enveloped transformation to the reference.
                XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
                reference.AddTransform(env);

                // Add the reference to the SignedXml object.
                signedXml.AddReference(reference);

                // Compute the signature.
                signedXml.ComputeSignature(); //throws exception from here.

                // Get the XML representation of the signature and save
                // it to an XmlElement object.
                XmlElement xmlDigitalSignature = signedXml.GetXml();

                // Append the element to the XML document.
                xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));

            }

    Is anyone faced same problem? can anyone provide solution for this?

    Thanks,

    Chirag

    Wednesday, June 29, 2016 11:52 AM

Answers

  • Hello,

    You want to target your application explicitly for 64-bit platform.

    I was getting "Out Of Memory" exception with "Any CPU", if "x64" is explicitly set, then no problems (I tested 364 MB).


    Mark this as answer if your problem is solved. Upvote if helpful.

    Wednesday, June 29, 2016 12:59 PM

All replies

  • Hello,

    You want to target your application explicitly for 64-bit platform.

    I was getting "Out Of Memory" exception with "Any CPU", if "x64" is explicitly set, then no problems (I tested 364 MB).


    Mark this as answer if your problem is solved. Upvote if helpful.

    Wednesday, June 29, 2016 12:59 PM
  • It is needed to mention that it ate about ~8GB of RAM to do that.  

    Mark this as answer if your problem is solved. Upvote if helpful.

    Wednesday, June 29, 2016 1:29 PM