Mono-LibreOffice System.TypeLoadException

Mar*_*rco 1 c# mono libreoffice ubuntu-11.10

在过去,我编写了一个C#库来使用OpenOffice,这在Windows中比在Ubuntu下使用Mono更好.
此库的一部分在此处作为已接受的答案发布.
在这些日子里,我发现Ubuntu决定转移到LibreOffice,所以我尝试使用LibreOffice最新的稳定版本.
虽然在Windows下它运行良好,但在Linux下我收到此错误:

Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.
Run Code Online (Sandbox Code Playgroud)

通常Mono告诉我们哪个库无法加载,所以我可以安装正确的包,一切都很好,但在这种情况下,我真的不知道什么是坏的.

我正在使用Ubuntu oneiric,我的库是用Framework 4.0编译的.
在Windows下我必须将其写入app.config:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

因为LibreOffice程序集使用Framework 2.0(我认为).

如何找到解决此错误的原因?
谢谢

更新:
即使使用Framework 2.0问题进行编译(如预期)也是如此.
问题(我认为)是Mono没有找到cli-uno-bridge包(可以在以前的Ubuntu版本上安装,现在标记为已取代),但我不能确定.

更新2:
我在Windows上创建了一个引用cli-uno dll的测试控制台应用程序(它们在GAC_32和GAC_MSIL中注册).

CONSOLE应用程序

static void Main(string[] args)
{
    Console.WriteLine("Starting");
    string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    string doc = Path.Combine(dir, "Liberatoria siti web.docx");
    using (QOpenOffice.OpenOffice oo = new QOpenOffice.OpenOffice())
    {
        if (!oo.Init()) return;
        oo.Load(doc, true);
        oo.ExportToPdf(Path.ChangeExtension(doc, ".pdf"));
    }
}
Run Code Online (Sandbox Code Playgroud)

图书馆:

using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.view;
using unoidl.com.sun.star.document;
using System.Collections.Generic;
using System.IO;
using System;

namespace QOpenOffice
{
    class OpenOffice : IDisposable
    {
        private XComponentContext context;
        private XMultiServiceFactory service;
        private XComponentLoader component;
        private XComponent doc;

        public bool Init()
        {
            Console.WriteLine("Entering Init()");
            try
            {
                context = uno.util.Bootstrap.bootstrap();
                service = (XMultiServiceFactory)context.getServiceManager();
                component = (XComponentLoader)service.createInstance("com.sun.star.frame.Desktop");
                XNameContainer filters = (XNameContainer)service.createInstance("com.sun.star.document.FilterFactory");
                return true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                return false;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但我无法看到"开始" !!!
如果我在应用程序上使用(...)发表评论,我会在控制台上看到一行...所以我认为它在DLL中有问题.在那里我无法"Entering Init()"在Init()上看到消息.未安装LibreOffice时的行为是相同的!!! try..catch块没有被执行...
我开始认为mono无法找到LibreOffice CLI库...
我使用updatedb然后locate找到它们,但我总是得到一个空的结果; 我不明白,在Windows上一切正常......

更新3:
汉斯评论后,我刚刚删除Init()了我的库中的所有内容,但错误仍然存​​在.所以我感动了

//private XComponentContext context;
//private XMultiServiceFactory service;
//private XComponentLoader component;
//private XComponent doc;
//private List<string> filters = new List<string>();

#region Constructors
public OpenOffice()
{
    Console.WriteLine("Entering Init()");
    try
    {
        var context = uno.util.Bootstrap.bootstrap();
        var service = (XMultiServiceFactory)context.getServiceManager();
        var component = (XComponentLoader)service.createInstance("com.sun.star.frame.Desktop");
    }
    catch (System.Exception ex)
    {
        Console.WriteLine(ex.Message);
        if (ex.InnerException != null)
            Console.WriteLine(ex.InnerException.Message);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在在控制台我能看到

开始

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集'cli_uretypes,Version = 1.0.8.0,Culture = neutral,PublicKeyToken = ce2cb7e279207b9e'或其依赖项之一.

这不能解决我的问题,但有帮助!!
问题是:为什么LibreOffice的Linux安装(安装包+ SDK)没有安装这个库?

Mar*_*rco 5

我终于回答了我的问题,但我要感谢@Hans帮助我找到隐藏的问题.
正如我写的那样,尝试使用LibreOffice运行一个简单的Mono应用程序,我收到了这个错误

未处理的异常:System.TypeLoadException:发生了类型加载异常.
[ERROR] FATAL UNHANDLED EXCEPTION:System.TypeLoadException:发生了类型加载异常.

没有办法让Mono告诉我哪个是错误,我的应用程序也没有写任何东西到控制台,所以我可以理解哪个部分/行引起了错误.
汉斯回答中的一段显示了我的方式

.NET框架具有真正的即时编译器.Mono没有,它有一个AOT(Ahead Of Time)编译器.换句话说,它积极地编译程序集中的所有代码,而不仅仅是要执行的代码.

所以当我宣布时

private XComponentContext context;
private XMultiServiceFactory service;
private XComponentLoader component;
private XComponent doc;
Run Code Online (Sandbox Code Playgroud)

Mono尝试在执行应用程序时找到引用的程序集,而不是在处理这些行时!考虑到这一点,我决定继续前进.
所以我删除了变量声明并使用了:

//private XComponentContext context;
//private XMultiServiceFactory service;
//private XComponentLoader component;

var context = uno.util.Bootstrap.bootstrap();
var service = (XMultiServiceFactory)context.getServiceManager();
var component = (XComponentLoader)service.createInstance(
    "com.sun.star.frame.Desktop");
Run Code Online (Sandbox Code Playgroud)

再次执行我的应用程序,我能够看到我预期的控制台消息,最后,当var context = ...我处理线路时

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集'cli_uretypes,Version = 1.0.8.0,Culture = neutral,PublicKeyToken = ce2cb7e279207b9e'或其依赖项之一.

所以我终于找到了问题:Ubuntu 11.10中的LibreOffice没有安装CLI interface package,这个软件包已经从当前的Ubuntu发行版中删除了.
即使我尝试手动安装其他较旧的软件包,甚至转换一些rpm软件包,我也无法将LibreOffice与Mono一起使用.
太糟糕了,即使因为之前使用OpenOffice进行分发,也有cli-uno-bridge包来做这项工作.希望将来更好......
我也尝试在AskUbuntu上发帖提问,但目前没有给出有用的答案.