Free Support Forum - groupdocs.com

eSigning API multiple calls issue in .NET

Hi,

We’re using the Signature API to sign a pdf in memory using memory streams. This works fine when called in a single thread. However, this is used in an intranet API and multiple calls are possible. And once the code is used by multiple requests this exception is thrown at the Signature.Sign method :

Cannot access a disposed object. Object name: ‘Document’.

The code is used in MVC Web API and following is the full code:

        using (var destination = new MemoryStream())
        {
            using (var ms = new MemoryStream(pdfBytes))
            {
                ms.CopyTo(destination);

                using (var signature = new Signature(ms))
                {
                    var digitalSignOptions = new DigitalSignOptions(CertificateStream)
                    {
                        
                        Left = left,
                        Top = top,
                        Height = height,
                        Password = DigitalSignaturePassword,
                        Contact = "test@test.com",
                        Reason = "Authorize abc",
                        Location = $"Test Location",
                        Visible = false,
                        
                    };



                    signature.Sign(destination, digitalSignOptions);
                }
            }

            return destination.ToArray();
        }

Please advise.

1 Like

@taxreturned,

Can you please specify the API version (e.g. 19.10, 20.1) that you integrated in the application?

20.1, the latest Nuget package.

1 Like

@taxreturned,

We are investigating this behavior. Your investigation ticket ID is SIGNATURENET-2609. As there is any further update, you’ll be notified.

@taxreturned,

Please have a look at the code, on line 3 are you are trying to copy pdfBytes to destination array?

  1. using (var destination = new MemoryStream()){
  2. using (var ms = new MemoryStream(pdfBytes)){
  3. ms.CopyTo(destination);

Please share following details:

  1. Please provide full example with pdfBytes source , example files etc
  2. Do not copy pdfBytes to destination stream
  3. We need to see the full example where pdfBytes were taken from. In this block we do not see any issues with multi threading since all variable are local?
  4. Is there some synchronization routines are being used?
  5. Are you facing this issue for all kind of file formats (Word, PDF etc) or just for PDF?

Hi,

Thanks for the reply.

I’ve since removed the copying of the source memory stream to the destination but still getting the error. Also, it’s worth knowing that this issue arises even when direct files are used instead of memory streams.

  1. I can’t send you the full code as it’s a complex Web API project. I’ve created a sample project which replicates the issue we’re having on the API.
  2. I’ve already removed this in the web API and the sample project and still getting the error.
  3. In the Web API, the pdf is generated dynamically into a byte array, in the sample, it’s loaded from the file system, both are giving the same result and having the same issue.
  4. There are no synchronisation routines, the web API call to sign the PDF is called from another app internally.
  5. We haven’t tried with Word documents as we use the functionality on PDFs.

Memory Issue On Signature.zip (180.1 KB)

1 Like

@taxreturned,

Thanks for the details. We’ll further investigate this issue and get back to you.

@taxreturned,

Please download and run this project.zip (179.3 KB). It uses pre-release 20.2 staging version of the API. And let us know if issue persists.

Thanks for that.

The project contains a reference to GroupDocs.Signature.20.2.0-alpha-20200219112656, and it’s not available in Nuget. Where can I download it?

@taxreturned,

You can get NuGet here (https://int.nugettest.org/packages/GroupDocs.Signature/20.2.0-alpha-20200219112656).

Thank you very much for this. The pre-release seems to have fixed the issue. Will do more tests and confirm. Is it safe to run this pre-release api in a production environment?

1 Like

@taxreturned,

This staging version has no changes except Pdf Digital Signing fix, next week we will publish official version with few other changes.
So please feel free to use exactly this version until February release.