Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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]);
        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!