Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue May 31, 2016 10:05 am

Hi,

I'm currently having an issue with Spire.Xls. My code is currently just opening a file, and checking that it doesn't have any issues. As the system I'm working on, we don't have control of the files that we are manipulating with the Spire library. The code is multithreaded, with threading logic being handled outside of the code block below. The code creates a seperate thread for the processing of a list of Excel files using Spire.XLS, sequencially. The other threads are used to process Word and PowerPoint files.

What is currently happening, is that when I stop the application it throws a null reference exception (see below). It also comes up with the following message "Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code)". I've been unable to track down the cause for this as processing of all the spreadsheet processing looks to have already completed and the exception and information provdied isn't that helpful. Looking at the exception and the extra information I found, it looks like the issue is actually in he Spire.XLS library. What I think is happening is that the workbook is loosing the worksheet objects, and when dispose is called it errors as there is an assumption that the workbook has worksheets.

As you can see from my code I've tried a few solutions already:
* Disposing the weeksheet objects
* Switching from LoadFromFile to LoadFromStream
* using a "Using" statement
* Disposing object after an manually when an exception occurs.

None of these solutions seem to have worked. I also have not been able to isolate a file as the cause. Try..Catch blocks appear to have no effect on handling this issue.

Are you able to provide any help, suggestions on how to prevent this?

Library version: 7.9.45.4040 (Evaluation)

Exception:
System.NullReferenceException was unhandled
Message: An unhandled exception of type 'System.NullReferenceException' occurred in Spire.XLS.dll
Additional information: Object reference not set to an instance of an object.

Extra info I was able to get:
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at spr8000.1(XlsWorksheet A_0, Dictionary`2 A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.ParseData(Dictionary`2 dictUpdated
SSTIndexes)
at Spire.Xls.Core.Spreadsheet.XlsWorksheetBase.ParseData()
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.40()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.ClearAll()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.DisposeAll()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close(Boolean SaveChanges, String F
ilename)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close(Boolean saveChanges)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Finalize()

Code:
Code: Select all
public OfficeFileValidationStatus Validate(string filePath)
      {
         OfficeFileValidationStatus fileStatus = OfficeFileValidationStatus.Pass;
         Workbook workbook = null;

         try
         {
            //using (workbook = new Workbook())
            //{

            FileStream x = new FileStream(filePath, FileMode.Open);

            workbook = new Workbook();

            //workbook.LoadFromFile(filePath);
            workbook.LoadFromStream(x);
               
            if (workbook == null || workbook.Worksheets == null)
            {
               fileStatus = OfficeFileValidationStatus.OtherError;
            }
            else
            {
               if (workbook.IsWindowProtection)
               {
                  fileStatus = OfficeFileValidationStatus.IsNonEditable;
               }

               foreach (Worksheet sheet in workbook.Worksheets)
               {
                  if (sheet.ProtectContents || sheet.ProtectScenarios)
                  {
                     fileStatus = OfficeFileValidationStatus.IsNonEditable;
                     //sheet.Dispose();
                     break;
                  }
                  //sheet.Dispose();
               }
            }
            //}
         }
         catch (Exception ex)
         {
            if (ex.Message.Contains("Workbook is protected and password wasn't specified.")
               || ex.Message.Contains("Invalid password."))
            {
               fileStatus = OfficeFileValidationStatus.PasswordRequired;
            }
            else if (ex.Message.Contains("Zip exception.Can't find local header signature - wrong file format or file is corrupt.")
               || ex.Message.Contains("Maximum number of extended formats exceeded.")
               || ex.Message.Contains("Cannot read that as a ZipFile")
               || ex.Message.Contains("Zip exception.Wrong Crc value.")
               || ex.Message.Contains("File does not contain workbook stream"))
            {
               fileStatus = OfficeFileValidationStatus.Corrupt;
            }
            else
            {
               fileStatus = OfficeFileValidationStatus.OtherError;
            }
         }
         finally
         {
            //if(workbook != null)
            //{
            //   workbook.Dispose();
            //}
            try
            {
               var x = workbook.Worksheets[0];
            }
            catch
            {
               workbook = new Workbook();
            }
            workbook = null;
         }

         return fileStatus;
      }

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Wed Jun 01, 2016 3:39 am

Hi,

Thanks for your posting
To help us replicate and investigate your issue, please share your excel file and tell us your system environment.
Thank you for further assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 01, 2016 8:43 am

Thanks for getting back. Unfortunetly I can't provide the file that is causing issues due to confidentiallity issues. I can attempt to provide information on the file below, in the hope that that might help. If you still need the file I'll see if I can create a dummy version of the file, but this really is a complex file and I might not be able to create it exactly.

File:
Extension: xlsx
Version: Excel 2007 (I think based on the "Print_Area" error)
Size: 7,940 KB
Number of worksheets: 36
Number of visibile worksheets: 12

When you open the file in Excel it comes up with the warning saying that it has a duplicate "Print_Area"
The workbook has linked content
The workbook has hidden columns
The workbook has hidden rows
The workbook uses pivot tables in several of the worksheets
Obviously the worksheets make extensive use of formulas
The is basic formatting. Grid lines, cell colour fill, etc.

Environment
OS: Windows 7
Ram: 16GB
CPU Intel Dual Core 3.0 GHz

Development in .Net 4.
Project type that the code is currently running is Console application.

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Wed Jun 01, 2016 9:00 am

Hi,

It is very difficult to replicate and resolve the issue if we don't have your excel file. Please give us a sample excel file which removes your confidential data. You can send your excel file to support@e-iceblue.com.

Please kindly note that we take customer's confidential information as serious as them. We will never publish or disclose any information of our customer. This is always the promise we keep to our customer and the regulation we must obey.

Thank you for further providing in advance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 01, 2016 10:52 am

Hi Amy,

Thanks for your reply. I appreciate that not having a document to test is at best a hinderance, at worst makes the situation impossible to diagnose. The sending/sharing of the file has nothing to do with yourselves, it's an internal policy that has no room for exceptions. I appreciate the reassurance on your own policies, it is most comforting.

I'm currently in the process of seeing if I can find what about the file is causing an issue, so I can create a sample file for you. As I previously said it is quite a complex workbook.

A bit more information for you that might help. Currently when the file initially throws an exception, prior to the null reference one, it is "Maximum number of extended formats exceeded.". I don't know if that means anything to you; from my own research it seems to be an issue going between version of Excel, but not something that should cause the null exception.

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Thu Jun 02, 2016 11:17 am

Hi Amy,

I haven't been able to create a dummy version of the document, due to its size and complication. Due to my company rules, as I mentioned earlier, I can't send you the original.

One thing I noticed during my attempt to create a dummy version, I noticed if I reduced the number of worksheets beyond a certain point it seem to stop erroring. Spire.XLS also stopped throwing the "Maximum number of extended formats exceeded." exception on the file. When I looked into it the number of exteneded formats was reduced. This makes me think that the cause of the unusual null reference exception is the number of extended formats in the document. When the xlsx is unzipped the styles.xml file is 10,945KB.

Are there any issues with the "Maximum number of extended formats exceeded." exception being thrown and the removal of objects that are referenced when dispose is called?

I understand this is difficult ticket to help, due to the lack of file.

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Fri Jun 03, 2016 11:37 am

Are you able to provide any information on this issue?

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Mon Jun 06, 2016 2:05 am

Hi,

Sorry for the delayed response. I am not in the office these days.
At present, the latest version is Spire.XLS Pack Version:7.10. Please try the version.
It is very difficult to do the investigation and find any ways can help if we don't have a document can replicate your issues.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Jun 06, 2016 9:23 am

Hi Amy,

Thank you for your reply. I've downloaded the latest version of Spire.Office for .Net (2.14), and I've tried that against my issue file. The unhandled exception from my earlier posts is still occurring. I've double checked the version of Spire.XLS that is being used is 7.10.6.4040.

As far as I can tell this issue only occurs when it throws the "Maximum number of extended formats exceeded." exception and then attempts to dispose of the workbook class. I've done some research into this and I've found that there are two limits for styles in Excel (4075 styles for Excel 2003 and 64000 for Excel 2007+). I've decompiled the issue Excel file and can confirm that there are roughly 63200 styles, so while close it is still under the official limit. So I now have two questions:
1) Why is it throwing the "Maximum number of extended formats exceeded." exception when the number of styles in the document is under.
2) Why is it throwing an exception when the Workbook dispose is called.
Obviously of the two questions the second is the most important.

My take on this, is that some object(s) which have it/their dispose method called by the Workbook or Worksheet dispose methods aren't raised when the "Maximum number of extended formats exceeded." exception is thrown. A solution would be to either ensure that the when the exception is thrown the necessary items are set to a default/neutral state which allow the dispose method to be called; or to put checks in the dispose methods of Workbook or Worksheet that checks to see if an object is null, and if it is don't call the dispose method on it.

As I have previously said, it is the company I work for policy to not disclose or share documents. We may create a dummy version, which in the current case isn't practical due to both the size and complexity of the file. I believe enough information has been provided in this thread for a developer with access to the source code to investigate the issue.

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Tue Jun 07, 2016 7:19 am

Hi,

I have forwarded all information you provided to our dev team. But our dev team told me that the information is not enough to make them carry out an investigation regarding the exceptions. We can do some simple samples to fix some options but we cannot make sure the fixes can resolve the issues exists in your excel file. Maybe the efforts we will do cannot help you and also wasting a lot of time to delay the speed of fixing your issues. You document is the key to fix your issues.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Tue Jun 07, 2016 9:39 am

Hello,

You can try to specify the excel version before loading the document like as below.
Code: Select all
workbook = new Workbook();
workbook.Version = ExcelVersion.Version2007;
workbook.LoadFromStream(x);

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Jun 07, 2016 2:45 pm

Hi Gary,

I had already tried specifying the Excel version, using both the 2007, 2010 and 2013 flags, but as I've updated the Spire.XLS library I've tried again. All three version resulted in the reported behaiour. I think I had the same idea you had that by forcing the version it would get past the issue.

I'm fast approaching the point where I need to tell my management what library to purchase. This issue causes a critical error crashing the entire system, with no way to handle it. At the moment I can't recommend Spire.Office, even though it is the current preferred library, as the inability to prevent or handle the critical issue makes the code unstable for our production environment. I need at the very minimum to be able to catch and handle the exception.

As I have repeated in the posts above, I am unable due to company policy to provide the file that is causing the issue. Also due to the complexity of the original file, it isn't possible to create a clean dummy version for you to test. I'm beginning to get the distinct impression that if I don't/can't provide a file for your developers to debug against then there is nothing you will do. Given my company's policy regarding documents this could be fatal issue that prevents us adopting your product.

I do find it hard, as a developer, to understand how with the information I've provided above isn't enough for an initial investigation by a develoer.

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Wed Jun 08, 2016 8:35 am

Hello,

Thanks for your response. Sorry for inconvenience caused by us, and we will try to look into the issue.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Jun 08, 2016 10:58 am

Hi Gary,

Thanks for your reply. I do have some good news. A colleage working on a different project has found an Excel file that exhibits the same fatal error, although the error message is different. I've included the file, and the error message and the stack trace. The file in question is a significantly less complex than the file I've previously had the issue with. Excel 2010 isn't able to open the file, although I am able to open in using LibreOffice Calc 5.

Error message: Root element is missing.
Stack trace:
System.NullReferenceException was unhandled
Message: An unhandled exception of type 'System.NullReferenceException' occurred in Spire.XLS.dll
Additional information: Object reference not set to an instance of an object.

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at spr8120.1(XlsWorksheet A_0, Dictionary`2 A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.ParseData(Dictionary`2 dictUpdatedSSTIndexes)
at Spire.Xls.Core.Spreadsheet.XlsWorksheetBase.ParseData()
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.40()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.ClearAll()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.DisposeAll()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close(Boolean SaveChanges, String Filename)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close(Boolean saveChanges)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Close()
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Finalize()

Hopefully this will be useful in identifying the underlying issue and fix it for both scenarios.
Attachments
Print.7z
(5.37 KiB) Downloaded 657 times

dgh8
 
Posts: 12
Joined: Fri Mar 04, 2016 4:24 pm

Thu Jun 09, 2016 3:53 am

Hi,

Thank you for the providing.
Our products are based on the specification of MS, if MS excel is unable to open the file, sorry that we also cannot do any operation for the file.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Return to Spire.XLS