FormatException when setting margins

Good day,

we got an issue when configuring margins on excel documents. However, this issue is kind of specific and only happens in the system environment of our customer, so we cannot provide clear steps to reproduce.

To start with, we using Aspose for .Net and have wrapped some functionallity in an own library. The background of this is, that we are then controlling the Aspose lib from our product, which is written in Delphi, using Crosstalk. This in general is not an issue and has worked fine for several years now. However it is kind of relevant, as the access to exceptions is reduced. When an exception is thrown in .Net, it will be reraised in the Delphi program, providing exception class and message. The stack is not accessable. We tried implementing an exception handler in our .Net wrapper which would verbose the stack to the disk, but according to the customer it does not exist. As we are not allowed to remotely access their server system, we are unable to validate this, so we basically do not have the stack.

The issue itself also is kind of obscure. After some time (which is different each time and we could not discover a pattern yet), we are getting System.FormatException with message

Input string was not in a correct format.

This exception is thrown during our call to set the margins on the excel documents. Our code in the wrapping dll is this:

        public void SetMargins(double marginTop, double marginRight, double marginBottom, double marginLeft,
            double marginHeader = -1, double marginFooter = -1)
        {
            try
            {
                _worksheet.PageSetup.TopMargin = marginTop;
                _worksheet.PageSetup.RightMargin = marginRight;
                _worksheet.PageSetup.BottomMargin = marginBottom;
                _worksheet.PageSetup.LeftMargin = marginLeft;

                _worksheet.PageSetup.HeaderMargin = marginHeader;
                _worksheet.PageSetup.FooterMargin = marginFooter;
            }
            catch (Exception e)
            {
                ExceptionLogger.LogExceptionToTemp(e);
                throw;
            }
        }

From screenshots of our software configration and logfiles we know that the params are called with following values:
image.png (2.4 KB)
The values are a bit odd as they are converted from twips to cm with some old legacy code. I never realized this before but now I will optimize this already in next step.

After the exceptions once occured, this happens on every excel document the customer trys to open (other office formats still can be processed correctly), until the service has been restarted. Then it works ‘for a while’ until it starts happening again.
We also have confirmed, that setting those margins on all documents is not an issue itself in general as we had been able to once process all documents with the code.
As they are the only customer with this issue and we cannot reproduce it locally or discover any pattern/cause for the problem it very likely much be related to their system in some way or due to unknown side effects, which we do not understand yet.
After we disabled margins, the error also does not happen any more in over two weeks now (before, the service had to be restarted multiple times a day due to the issue), so it is very likely confirmed, it must be related to the margins in some way.

The software runs on a Windows Server 2016 Standard Edition with German locale (as far as we know).

I am aware this might be a difficult issue to answer, but maybe you know any similar issues which could have been resolved or maybe can discover potential errors in the Aspose code, which may cause such a FormatException.

I would appreciate if you can provide some feedback to this, kind of very special, issue.
Kind Regards,
Daniel

@Serraniel,
We have reviewed your issue but are afraid to share that without a sample file, it is not possible to reproduce this issue. Could you please try to provide some sample files and a runnable sample code for our testing or any other steps or information that can be helpful to observe the issue? It will help us to reproduce the issue and provide assistance at the earliest.

@Serraniel,
We have further analyzed the issue and would like to share that while setting the margin, we do not parse the double value and just accept it as it is. Also there was little bug in quite older versions for the German locale while opening and saving XLSX or XML but it was resolved. It is suggested, that you should use the latest version if not used earlier.

Please provide the following information:

  1. Which product version are you using?
  2. Which file format is used for saving the file?

Hi,

thanks for your response. They are currently running with the 21.07 version. The exception had been raised independent from the save format and on every document, also an empty document, when it reached the state it would happen.
We´ll try to investigate further if there is a way which we can clearly reproduce the issue. Thanks for your help.

Daniel

@Serraniel,
You are welcome and take your time to devise some mechanism to reproduce this issue at your end. It will help us to assist you in a timely manner.