This project has moved and is read-only. For the latest updates, please go here.

Exception:The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception.

Aug 3, 2012 at 8:40 PM

First off:   Thank you for a wonderful product..

I have created a small console application that converts a dataTable to Excel using closedXML. This is deployed on a windows server 2008.  I get the following error:

The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception.
   at ClosedXML.Excel.XLWorkbook.set_DefaultRowHeight(Double value)
   at ClosedXML.Excel.XLWorkbook..ctor(XLEventTracking eventTracking)
   at ClosedXML.Excel.XLWorkbook..ctor()
   at vendorAppNotification.VAnotify._getList()
   at vendorAppNotification.VAnotify.Main(String[] args)


Here is the code that throws the error:

    // convert the datatable to excel
            if (d.Rows.Count > 0)
                var workbook = new ClosedXML.Excel.XLWorkbook();
                d.TableName = FILENAME;    // this is needed for the XLSx as the work book name
                workbook.SaveAs(FILEPATH + FILENAME); // save the excel                


The XLSX is created properly and saved when I run the program on my PC. I have office 2010 and there is no problem. The server does not have any form of office. Could this be an issue OR maybe a permission problem as I have limited rights on the server.

Best Regards,

Aug 3, 2012 at 8:58 PM

I honestly don't know what's going on there and the information is not enough for me to work with :(

Aug 3, 2012 at 9:06 PM

Hello MDelon,

That was very quick. I browsed the code and figured it out. the default document format was missing.  I Just dropped in the DocumentFormat.OpenXML.dll  in the same folder where the executable is and I have the Excel.