Search code examples
c#excelgembox-spreadsheet

error while loading .xlsx with Gembox.Spreadsheet


I have the following problem : when I try to load an XML based Excel file (.xlsx) and even if I set the LoadOption to XlsxDefault the program throws the error Reading error: file is not a valid OLE2 Compound File.".

it don't throw any exceptions if I try to load the .XLS-exported version of the workbook, seems like ExcelFile.Load method cannot open xml based excel files.

I Tried to replace the path of my spreadsheet with one .xlsx file downloaded on The Gembox example page but it didn't change anything. currently my only way to open a Excel Workbook is to load a .xls version of the file.

EDIT : I can open the .xlsx files with excel without any problems

EDIT2: I Wasn't able to reproduce the problem in another solution so I Think that another part of my soft is responsible of my problem


Solution

  • That is a handled exception, GemBox.Spreadsheet internally does throw and handle that exception in order to determine if it's an encrypted XLSX or not.

    Two things are required in order for you to receive that error in Visual Studio.

    1. In the "Debug" -> "Options..." dialog window, under the "Debugging" -> "General" section, you need to have "Enable Just My Code" setting disabled.
    2. In the "Debug" -> "Windows" -> "Exception Settings" dialog window, under the "Common Language Runtime Exceptions" category node, you need to have "<All Common Language Runtime Exceptions not in this list>" setting enabled.

    In order to resolve this you can either enable the "Enable Just My Code" setting or disable the "<All Common Language Runtime Exceptions not in this list>" setting.

    As an FYI, from MSDN:

    If you check a given exception, debugger execution will break wherever the exception is thrown, regardless of whether it is handled or unhandled. At this point the exception is called a first chance exception.