The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception
c#
Solution
Thought would delete this post, but might help someone in future....All i had to do was reference one more DLL DocumentFormat.OpenXml.dll . Works perfectly now!
Problem
``` using ClosedXML.Excel; class XLSXWriter : BExporter { private readonly string _fName; public XLSXWriter(string fileName) { _fName = fileName; } public override void Export(IEnumerable<AnimalData> animals) { var workBook = new XLWorkbook(); <---Throws an exception var workSheet = workBook.Worksheets.Add("MySheet"); workSheet.Cell("A1").Value = "Hello World"; FileStream fs = new FileStream(_fName, FileMode.Create); workBook.SaveAs(fs); fs.Close(); } } ``` Just trying this library `ClosedXML.dll`, and it throws an exception can't figure out what could be the problem. I get the `_fName` from the `savefiledialog`. Ideas anybody?