【问题标题】:Bootstrap Uno API LibreOffice exceptionBootstrap Uno API LibreOffice 异常
【发布时间】:2015-08-06 12:38:19
【问题描述】:

使用以下代码:

static void Main()
{
    try
    {
        var context = uno.util.Bootstrap.bootstrap();
    }
    catch (Exception ex)
    {
       Console.WriteLine(ex.toString());
    }
}

我可以启动 LibreOffice 的 Writer。这适用于版本 4.4.4,但在安装版本 5.0.0 和新 SDK Bootstrap.bootstrap() 后会引发异常:

"External component has thrown an exception"

有没有人遇到过同样的问题或解决方案? (.NET 4.0、Windows 7 64 位、LibreOffice 5.0 Lite)

【问题讨论】:

  • 抛出的异常是否有任何内部异常,可能包含更多信息,例如哪个外部组件源自它?
  • 以下是异常 cli_cppuhelper.dll cppu.bootstrap 中发生的“System.Runtime.InteropServices.SEHException”类型的第一次机会异常(参考<:sun::star::uno:: xcomponentcontext>*
  • bug tracker 上引用了此问题。它确认将C:\Program Files\LibreOffice\program 添加到环境变量“PATH”可以解决大多数人的问题。

标签: c# exception uno


【解决方案1】:

我已经通过在启动soffice.exe 服务器之前设置UNO_PATH 环境变量来解决这个问题:

using static System.Environment;

var unoPath = @"C:\Program Files\LibreOffice 5\program"
// when running 32-bit LibreOffice on a 64-bit system, the path will be in Program Files (x86)
// var unoPath = @"C:\Program Files (x86)\LibreOffice 5\program"

SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process);
SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process);

这是必需的,因为 LibreOffice 5 的程序目录不再具有 UNO 层所需的“URE”子目录(以前的版本有)。

【讨论】:

  • 谢谢,但这个解决方案并不总是有效。我已经在不同的 Windows 版本下进行了测试,有些可以,有些不行。
  • 感谢您的通知,我在 Windows Server 2012 R2 上使用它,运行良好。这是代码: Environment.SetEnvironmentVariable("UNO_PATH", unoPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + @";" + unoPath, EnvironmentVariableTarget.Process);
  • 谢谢它完美地工作,但只有当我有 libreoffice 32 位,libreoffice 64 位我仍然有错误,有什么建议吗?
  • @Alkampfer 您是否尝试在 x64 版本中使用“Program Files”而不是“Program Files (x86)”?
【解决方案2】:

要获取 LibreOffice 安装的路径,您可以询问例如Windows 注册表。在 C# 中是这样的:

    String unoPath = "";
    // access 32bit registry entry for latest LibreOffice for Current User
    Microsoft.Win32.RegistryKey hkcuView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, Microsoft.Win32.RegistryView.Registry32);
    Microsoft.Win32.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
    {
        // access 32bit registry entry for latest LibreOffice for Local Machine (All Users)
        Microsoft.Win32.RegistryKey hklmView32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32);
        Microsoft.Win32.RegistryKey hklmUnoInstallPathKey = hklmView32.OpenSubKey(@"SOFTWARE\LibreOffice\UNO\InstallPath", false);
        if (hklmUnoInstallPathKey != null && hklmUnoInstallPathKey.ValueCount > 0)
        {
            unoPath = (string)hklmUnoInstallPathKey.GetValue(hklmUnoInstallPathKey.GetValueNames()[hklmUnoInstallPathKey.ValueCount - 1]);
        }
    }

那你就可以用Funbit[https://stackoverflow.com/a/31937114/2936206]的回答了

【讨论】:

    【解决方案3】:

    我发现最简单的方法是将 URE 文件夹从以前的 LibreOffice 版本复制到 LibreOffice 5。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 2014-10-16
      • 2016-03-31
      • 1970-01-01
      相关资源
      最近更新 更多