Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly Load error from DocumentFormat.OpenXml

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.

like image 516
Charles Bretana Avatar asked Apr 04 '18 13:04

Charles Bretana


2 Answers

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

like image 50
chester89 Avatar answered Oct 10 '22 01:10

chester89


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.

like image 36
Cee McSharpface Avatar answered Oct 10 '22 01:10

Cee McSharpface