C# LibreOffice SDK

1337/5000
I am developing a desktop application in .NET (C # + WPF) and my machine works correctly, I can make the LibreOffice call, open a file and customize the interface all through my .NET application, but in order to work, it is necessary the version of the SDK is the same as that of LibreOffice installed on the machine, and the architecture of the application should be the same as that of LibreOffice (32 or 64 bits).

To work the integration, I had to add in the references of my project the DLLs that comes along with the SDK:

  • cli_basetypes.dll
  • cli_cppuhelper.dll
  • cli_oootypes.dll
  • cli_ure.dll
  • cli_uretypes.dll

So at first all right, but my question is this:
I developed the application using LibreOffice 6.1 along with the SDK of the same version and now I need the application to run on another machine with a lower version of LibreOffice, which I can not currently get, with the following error occurring:

  • System.IO.FileNotFoundException: Could not load file or assembly ‘cli_cppuhelper.dll’ or one of its dependencies. The specified module could not be found.

Is it possible to run the application on another machine with a different version of LibreOffice? As?
Also, is it possible to avoid errors because the application is developed in 64bit and LibreOffice installed is 32bit for example?

After many attempts I was able to solve the problem.

It was necessary to override the AssemblyResolve event to fetch the LibreOffice DLLs from the GAC (C:\Windows\Microsoft.NET\assembly).

In addition the application must run with the same LibreOffice architecture installed so it was necessary to generate two executables, one 32bits and another 64bits (checking/unchecking the “32-bit Preferred” project property) so that the AssemblyResolve event finds the right DLL in GAC.

Another necessary change was necessary to set in the environment variable “UNO_PATH” that can be found in the Windows registry;

 string unoPath = "";
    RegistryKey hkcuView32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Default);
    RegistryKey hkcuUnoInstallPathKey = hkcuView32.OpenSubKey(@"SOFTWARE\LibreOffice\UNO\InstallPath", false);
    if (hkcuUnoInstallPathKey != null && hkcuUnoInstallPathKey.ValueCount > 0)
    {
    	unoPath = (string)hkcuUnoInstallPathKey.GetValue(hkcuUnoInstallPathKey.GetValueNames()[hkcuUnoInstallPathKey.ValueCount - 1]);
    }
    else
    {
    	RegistryKey hklmView32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
    	RegistryKey hklmUnoInstallPathKey = hklmView32.OpenSubKey(@"SOFTWARE\LibreOffice\UNO\InstallPath", false);
    	if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0)
    	{
    		unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]);
    	}
    }
    
    Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
    Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process);

After this steps, my application worked perfectly!