This project has moved. For the latest updates, please go here.

'ClosedXML.Excel.XLWorkbook' threw an exception

May 31, 2012 at 8:06 AM
Edited May 31, 2012 at 8:07 AM

hi to all,

I have made a small app that reads data from a mysql DB and i want to export them in to excel.

I am using ClosedXML and in my proggrammer pc all works fine.

I copy ALL the files in to another pc but when i am pressing the button to export into excel exception message appers

Can anyone help me?

Thanks in advance

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.TypeInitializationException: The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at ClosedXML.Excel.XLWorkbook..cctor()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

   --- End of inner exception stack trace ---
   at ClosedXML.Excel.XLWorkbook..ctor()
   at WindowsFormsApplication1.trdrForm.Excelexport() in C:\sc\src\kravmaga\temp\WindowsFormsApplication1\WindowsFormsApplication1\EditCustFrm.cs:line 378
   at WindowsFormsApplication1.trdrForm.dgvTrans_CellMouseDown(Object sender, DataGridViewCellMouseEventArgs e) in C:\sc\src\kravmaga\temp\WindowsFormsApplication1\WindowsFormsApplication1\EditCustFrm.cs:line 346
   at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
   at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
KRAVMAGAHELLAS
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/vagelis/Desktop/kravmaga/KRAVMAGAHELLAS.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5458 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
MySql.Data
    Assembly Version: 6.4.4.0
    Win32 Version: 6.4.4.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/MySql.Data/6.4.4.0__c5687fc88969c44d/MySql.Data.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
ClosedXML
    Assembly Version: 0.65.2.0
    Win32 Version: 0.65.2.0
    CodeBase: file:///C:/Users/vagelis/Desktop/kravmaga/ClosedXML.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:


    


When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Coordinator
May 31, 2012 at 3:04 PM

The application can't find or doesn't have permission over the file DocumentFormat.OpenXml.dll

DocumentFormat.OpenXml
Sep 24, 2012 at 11:25 PM

Hello all!,

Im having same problem. Im receiving the exception:

Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.

This happens on productive server where I have no access. When I deployed I checked the 'Copy Local' property and all dll's have it set to true. I checked and the productive server bin folder contains the files: ClosedXML.dll, DocumentFormat.OpenXml.dll and WindowsBase.dll. Do I need to add any other file there?

Does the DocumentFormat.OpenXML.dll be in the GAC as a mandatory requirement?

Any help will be appreciated. Thanks!

Coordinator
Sep 25, 2012 at 3:12 AM

They don't have to be in the GAC, just in the bin folder. Make sure the account the application is running on does have access to it.

Oct 3, 2012 at 1:16 PM
Edited Oct 3, 2012 at 2:08 PM

Error is caused by the lack of assembly DocumentFormat.OpenXml
"Could not load file or assembly \" DocumentFormat.OpenXml, Version = 2.0.5022.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 \ "or one of its dependencies. Can not find the file specified.": "DocumentFormat.OpenXml, Version = 2.0.5022.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "

DocumentFormat.OpenXML.dll be in the GAC or  in folder /bin/debug.

DocumentFormat.OpenXML.dll was in the GAC on first PC ,it is absent in to another pc

See Documentation http://closedxml.codeplex.com/documentation

Requirements:

To use ClosedXML you must reference the following DLL: DocumentFormat.OpenXml.dll (part of MS Open XML SDK 2.0)

Load DocumentFormat.OpenXml.dll

Oct 30, 2013 at 1:11 AM
I'm seeing this sporadically too. Assembly is in the bin, app has access to it, it just randomly fails to load it. I'm only seeing this through ELMAH error log notifications and I haven't been able to reproduce it on demand. I don't have an answer for it, but I'll echo feedback from others that it's failing at various times for no explainable reason.