8

I get an error using the Microsoft ClosedXml and DocumentFormat.OpenXml NuGet utility packages. After I updated these NuGet packages, (from version 2.7.2 to version 2.8.1), I now get this exception:

Exception System.IO.FileLoadException: 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)

When I look at the relevant assembly in my solution project, it references the correct version, (2.8.1). Looking at the NuGet package manager, there are no references to the old 2.7.2 version (4 projects have references to the new version - 2.8.1). I can find no mention in any of the project references to version 2.7.2. The file in the executing application folder is also the correct one (2.8.1) (from looking at the details tab of the project properties window). Where else in my solution might this reference to the old version number (which apparently is causing this exception) be located?

Additional info: I have done a grep on all the files (including binaries) in the application directory where this is executing, including subdirectories, and the string 2.7.2 is nowhere to be found.

Also, When I debug this in Visual Studio, it works without throwing an exception. But when I run it in the deployed build folder I get the FileLoadException.

Alex B
  • 15
  • 7
Charles Bretana
  • 143,358
  • 22
  • 150
  • 216
  • 1
    This turned out to be a bug in the recently released version of ClosedXml (ver 0.91.0) in the way it was packaged for nuGet, in that it was trying to load a specific (older) version of DocumentFormat.OpenXml (version 2.72) which it internally was not compatible with. – Charles Bretana Apr 05 '18 at 12:34
  • I am having the same issue currently. How did you resolve this? – thebenman Apr 12 '18 at 10:36
  • I have closedXML version 0.91.0.0 and in the package.config the openxml version is 2.7.2 but the error message says it looks for openxml with version number 2.7.2.0. Do you have any idea on how to resolve this. – thebenman Apr 12 '18 at 10:53
  • 1
    Yes, there is a bug in the NuGet package that the developer released. I emailed back and forth with him, and he released a "corrected" version (0.92.1), that was *still* messed up. So I solved this by regressing back to closedXml 0.90.0 and DocumentFormat.openxml version number 2.7.2.0 – Charles Bretana Apr 12 '18 at 23:20
  • I was referencing this assembly in two different projects (different versions in each). Removing the package from one of the projects solved this for me – mark_h Feb 01 '19 at 08:49

3 Answers3

2

I just hit the same problem - ClosedXML 0.94.0 with DocumentFormat.OpenXML 2.10.0.
Works fine on dev machine, fails to find correct assembly when deployed to the server. I'm using .NET 4.7.2
Tried different things, nothing worked until I added binding redirect from 2.7.2 to 2.10.0

chester89
  • 8,328
  • 17
  • 68
  • 113
1

The package was buggy. I upgraded to 2.10.0 which came out recently, and all problems related to manifest mismatch went away.

Using the nuget package version of DocumentFormat.OpenXml.dll version 2.10.0 last stable from Microsoft means that the build output will contain only a DocumentFormat.OpenXml.dll being the correct version and only file required at runtime, and no longer a DocumentFormat.OpenXml.a.b.c.dll - be sure to remove that.

The 2.10.0 still supports older versions of the .NET framework and passed all tests in my case, your mileage may vary.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77
0

I just simple way to solve it.

  • Delete the reference in "references" in Solution Explorer
  • Add it again through Project->Add Reference->search for the name of the reference that was causing the error, select it, and add it.

It was solved for me like a charm.