Could not load file or assembly 'DocumentFormat.OpenXml - Again

2

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:

enter image description here

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?

vb.net
closedxml
asked on Stack Overflow May 8, 2018 by J R • edited May 8, 2018 by J R

1 Answer

2

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.

answered on Stack Overflow May 8, 2018 by b.pell

User contributions licensed under CC BY-SA 3.0