Reputation: 259
It seems that this problem is a very popular one, and I've already read nearly a dozen of similar questions, but all offer the same solution (install and reference DocumentFormat.OpenXml 2.5), which I already did, and it's still not working.
I am using Visual Studio 2012, referencing ClosedXML version 0.93 and it's dependency DocumentFormat.OpenXML version 2.5 in my project. Both .dll files are stored next to .exe file of my project. Visual Studio appears to see these references:
At the top of my code, I also have:
Imports DocumentFormat.OpenXml
Imports ClosedXML
However, when I call a simple test code,
Dim workbook = New ClosedXML.Excel.XLWorkbook()
Dim worksheet = workbook.Worksheets.Add("Sample Sheet")
worksheet.Cell("A1").Value = "Hello World!"
workbook.SaveAs("HelloWorld.xlsx")
I get an error, saying:
An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll
Additional information: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.7.2.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm at loss as to why this error occurs. If I write DocumentFormat.OpenXml. in my code, I get a list of suggested functions in that library, so the references must be loaded properly.
Can anyone help, please?
Upvotes: 3
Views: 6047
Reputation: 56
add document.openxml dll refernce into your project, you can get this dll through nuget package manager(please install required version of dll)
Upvotes: 0
Reputation: 1
you have to go to nugget and update the document xml reference to the latest one which is 2.7 and the issue is fixed
Upvotes: 0
Reputation: 4308
Have you noted that in the screen shot you're using version 2.5 in the references for the OpenXml assembly, but the exception message is referencing the newer 2.7.2? That could be your issue. It could be that you've referenced 2.5, but the "ClosedXML" is expecting 2.7.2 and when it doesn't find it tosses an error?
I would get 2.7.2, update your reference and then see if that works.
Upvotes: 2