DocumentFormat.OpenXml in Ubuntu server
Asked Answered
I

1

10

I have a basic C# application where Open XML SDK is used. I want to make it run in my Nginx & Ubuntu & DigitalOcean server.

The application compiles and works well in Windows, and my Mac with mono. Then, I installed mono in the Ubuntu server, and scp the .exe file to the server, and run mono ConsoleApplication2.exe, it returned the following error:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
  at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

I have found this link, it seems that the problem comes from the version of DocumentFormat.OpenXml. But how could I install its right version in a Ubuntu server?

Could anyone help?

Update 1: Then, I tried to install Open XML SDK 2.6.1, but there is no makefile. Otherwise, for Open XML SDK 2.5, I don't know where to find a release distribution.

Update 2: I should have tried build.open-xml-sdk.sh... I tried to run it in the server, but it gives an error. Does anyone know what's wrong here?

Update 3: I uninstalled mono, and followed this link:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mono-complete

mono was re-installed successfully. Then I tried build.open-xml-sdk.sh again, but it returned the same error.

Update 4: Following the comment of ZagNut, I tried to add DLLs to GAC. I noticed two things:

1) I downloaded the source code and generated DocumentFormat.OpenXml.dll and System.IO.Packaging.dll, they made my program compile well in Visual Studio. However, when i tried to add them to GAC by gacutil, it tells me they need a strong name.

2) Then I tried to add strong name to them by following this page, I realised that the new 2 dlls could not work correctly in Visual Studio anymore:

enter image description here

Infer answered 12/9, 2016 at 3:57 Comment(5)
have you seen this "github.com/OfficeDev/Open-XML-SDK/blob/vNext/…"?Devonna
I tried build.open-xml-sdk.sh, but it returned an error. Please see my OP...Infer
Sorry, the link you gave is invalid...Infer
pardon. writing from cellphone. mono-project.com/docs/getting-started/install/linuxDevonna
Please see my Update 3Infer
C
1

just put the binaries you need alongside your application executable.

for the binaries, you can build it yourself: https://github.com/OfficeDev/Open-XML-SDK

or download from below and just extract the binaries using Universal Extractor or installing it and finding them.

2.0: https://www.microsoft.com/en-us/download/details.aspx?id=5124

2.5: https://www.microsoft.com/en-us/download/details.aspx?id=30425

Crosstie answered 20/9, 2016 at 18:14 Comment(6)
Thanks for links for 2.0 and 2.5... but I am talking about installing them in Ubuntu server, rather than in Windows...Infer
ok extract the binaries and add them to the GAC: mono-project.com/docs/advanced/assemblies-and-the-gacCrosstie
Please see my Update 4Infer
ugh. and it doesn't work if you just drop the dlls in the directory next to the executable? if Mono works like .NET, it will automatically search there for the dlls. If it works, you could then explicitly reference them in your project and they should always be included with your builds. you won't have to string name them, then.Crosstie
See this especially regarding probing. It should look in the same directory as the executing assembly for those dlls.Crosstie
Indeed, it works... Namely, 1) download and install the .msi from Microsoft site, and copy DocumentFormat.OpenXml.dll to the Ubuntu server; 2) build Sample.exe with the same dll in Visual Studio, and copy Sample.exe to the Ubuntu server, in the SAME folder as the previous dll; 3) mono Sample.exe works.Infer

© 2022 - 2024 — McMap. All rights reserved.