GcPdfDocument.Load looking for BouncyCastle.Cryptography.dll

Posted by: bill.emerson on 9 July 2025, 2:45 pm EST

  • Posted 9 July 2025, 2:45 pm EST - Updated 10 July 2025, 7:13 am EST

    We have recently run into a situation that I cannot find an explanation for. We have a new client that is attempting to generate a PDF and on the call to GcPdfDocument.Load the following exception is thrown:

    Unexpected exception occurred while parsing PDF document. Could not load file or assembly ‘BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938’ or one of its dependencies. The system cannot find the file specified.

    The snippet of C# code that is throwing this exception is:

    [code] GcPdfDocument form = new GcPdfDocument();

    try
    {
    	form.Load(ms);
    }
    catch (Exception ex)
    {
    	throw;
    }[/code]
    

    We don’t have any references to BouncyCastle in our API and we do not deploy this DLL with our solution. I have obtained a copy of the PDF being processed and can process it in my development environment so I don’t think there is anything particular to this PDF that requires some type of crypto processing.

    Can anyone help determine why we might be seeing this exception?

    Thank you!

  • Posted 10 July 2025, 9:44 am EST

    Hi Bill,

    Unfortunately, we could not reproduce the issue on our end.

    Just for your information, GcPdfDocument has a dependency on the BouncyCastle.Cryptography package. This is also listed under the Dependencies tab on our NuGet page: https://www.nuget.org/packages/DS.Documents.Pdf#dependencies-body-tab

    To help us investigate further, could you please:

    1. Share the PDF file that triggers the issue? If the PDF contains confidential data, you can submit it via our private support portal by creating a new support case.

    2. Let us know the version of GcPdfDocument you are using, so we can test accordingly.

    3. Provide a screenshot showing all the DLL references in your project, so we can review the dependencies.

    4. Let us know the client environment details, such as the operating system, and whether there are any differences between their setup and yours that might be causing the issue.

    Best Regards,

    Kartik

  • Posted 11 July 2025, 10:05 am EST

    Hi Kartik,

    Thank you for your quick reply. I thought I had attached the PDF that triggered this error to this topic however I don’t see it. I have attempted to re-attach it.

    The version of DS.Documents.Pdf.dll we are running is 7.2.5.0.

    The Mescius related DLLs in our project include:

    DS.Documents.Html.dll

    DS.Documents.Imaging.dll

    DS.Documents.Pdf.dll

    Our solution is a Web based API running under IIS, the OS is Windows Server 2019 (I am running Windows 11 on my workstation). We have this same solution running at a number of other clients with this same configuration, this is the first time we have run into this issue.

    Please let me know if you need any additional information.

    570BA 179-2023.zip

  • Posted 14 July 2025, 1:02 pm EST - Updated 14 July 2025, 1:08 pm EST

    Hi Bill,

    Thank you for the details and for sharing the PDF file.

    We’ve tested the provided document in a similar environment using DS.Documents.Pdf.dll version 7.2.5, and the PDF loads successfully, both with and without the BouncyCastle.Cryptography DLL present in the project. Based on this, it appears that the presence of the BouncyCastle assembly may not be the root cause of the exception.

    To help us investigate further, we would need a minimal reproducible project or a sample deployment that triggers the exception on your client’s machine with the illustrative video recording. This will allow us to identify any environment-specific or deployment-specific issues on IIS.

    You can further refer to the attached sample application used to investigate the issue on our end, with the working screenshot and the system configurations.

    Attachment: DsPdfWebApi.zip

    Working:

    System Configurations:

    Best Regards,

    Chirag Gupta

  • Posted 7 August 2025, 8:35 am EST - Updated 7 August 2025, 8:40 am EST

    Hello Chirag,

    Thank you once again for your detailed response. We also have not been able to recreate this in any of our development and QA environments either (and at a number of our other clients).

    We did put the BouncyCastle.Cryptography.dll in place at the client where this is happening and we were able to get by the issue. However we bumped into a second issue when trying to parse through the fields on in the PDF. This is the same PDF that was uploaded on this post earlier.

    I am hoping you will see something in the stack trace that will help determine what might be causing this error. Please see the StackTrace.jpg attachment

    .

    I have also attached a code snippet from our app that indicates the specific call where this is occurring..

    Please take a look and let me know if you can determine why this might be happening. Again, the PDF that this is occurring in was attached earlier to this post.

    Thanks again for all the help. You guys are great!

    Bill

  • Posted 8 August 2025, 12:41 am EST

    Hi,

    It’s great that the previous issue is resolved.

    Regarding the new issue you reported, we are not able to replicate this on our end. The DsPdF API successfully fetches the fonts from the widget’s default appearance. Please refer to the attached sample and the screen recording that illustrates smooth working on Windows 11 and Windows Server 2019 machines (see below).

    Additionally, as per our observations and the stack trace, it seems like the font properties are fetched from a null font. As some of the fonts are null in the widget, it is not possible to directly get the properties from that font.

    Could you please share the following to further investigate the issue:

    1. A minimal working sample replicating the issue. You can also modify and share the attached sample.
    2. A demonstration video of the issue.

    Kind Regards,

    Chirag Gupta

    Attachment: DsPdfWebApi.zip

    Working:

  • Posted 11 August 2025, 3:07 pm EST

    Hi Chirag,

    I was able to replicate the null reference issue our client is seeing. Simply referencing the widget.DefaultAppearance.Font property (as I did in the highlighted code in my previous post) on a widget that doesn’t have a default font defined for it, causes a null reference exception. In the PDF attached to this post, none of the checkbox fields have fonts defined. I was able to cause the error by referencing the font on one of these fields/widgets.

    I can code around this issue our code but I do think you will want to take a look at it. The proper results (in my opinion) would be to return a null object and not to throw an exception. Particularly because it wouldn’t allow code such as:

    if ( widget.DefaultAppearance.Font == null )

    This would throw an exception when simply checking to see if the font is set.

    Thanks again for your quick responses.

    Bill

  • Posted 12 August 2025, 10:56 am EST

    Hi Bill,

    Thank you for sharing the details.

    Unfortunately, we were unable to reproduce the issue you mentioned on our end. Please refer to the video shared in our previous response, where none of the fonts fetched using widget.DefaultAppearance.Font throw a NullReferenceException when using your PDF file.

    If you are encountering the exception specifically in your main project, could you please update our sample project with your code and share it with us? This will help us investigate further and provide better assistance.

    Best Regards,

    Kartik

  • Posted 13 August 2025, 1:24 pm EST

    Hello,

    I was able to take the example code you provided (DsPdfWebApi.zip) and make a change to it that appears to be causing the issue in our solution. For some reason the following line of code causes the null reference exception to be thrown when the Font property is referenced later in the code:

    if (field is CheckBoxField && ((CheckBoxField)field).Widget != null)

    I have attached an updated version of your example that includes this line and it later throws the exception when the following line of code is called in the PrepareField method:

    var fieldFont = widget.DefaultAppearance.Font;

    Please take a look and let me know if there is something I am doing wrong in our code or, if not, what can be done to correct this issue.

    Thank you again,

    Bill

    UpdatedMesciusExample.zip

  • Posted 14 August 2025, 12:35 am EST

    Hi,

    Thanks for sharing the details.

    We can reproduce the behavior on our end. We are discussing this matter with the concerned development team and will update you as soon as we get any information from their end.

    Internal Tracking ID: DOC-7050

    Kind Regards,

    Chirag Gupta

  • Posted 11 September 2025, 11:24 am EST

    Hello,

    Would it be possible to get an update on Internal Tracking ID: DOC-7050? We have a client that is looking for a fix and I would like to provide a timeframe.

    Thank you!

    Bill

  • Posted 11 September 2025, 11:00 pm EST

    Hi Bill,

    We have reached out to our development team to obtain a timeframe for resolving this issue. We will get back to you as soon as we get any update from their end.

    Kind Regards,

    Chirag Gupta

  • Posted 12 September 2025, 1:49 pm EST

    Hi Bill,

    Thanks for your patience. The issue will be resolved in the DsPdf Version 8.2.1.

    The cause of the issue is that accessing the widget annotation of the checkbox creates an annotation that is not added into the PDF; therefore, accessing the font of such annotations results in System.NullReferenceException.

    As a workaround till DsPdf Version 8.2.0, we would recommend you modify the check in one of the following ways:

    1. Remove the check for the checkbox.Widget.
    2. Include the check for the checkbox.Widget.Page in addition to checking checkbox.Widget.
    3. Check for widget count instead of accessing the single widget.

    Please refer to the updated sample that demonstrates all three approaches and works perfectly without any issues.

    Kind Regards,

    Chirag Gupta

    Attachment: DsPdfWebApi.zip

  • Posted 14 October 2025, 2:48 am EST

    Hi Bill,

    The issue has been fixed in the DsPdf Version 8.2.1. The NuGet package of this version can be downloaded from https://www.nuget.org/api/v2/package/DS.Documents.Pdf/8.2.1.

    Please let us know if you encounter any further issues or require additional assistance.

    Kind Regards,

    Chirag

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels