单LibreOffice的System.TypeLoadException [英] Mono-LibreOffice System.TypeLoadException

查看:224
本文介绍了单LibreOffice的System.TypeLoadException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去我写了一个C#库与OpenOffice的工作,这个工作既精在Windows比在Ubuntu下使用Mono这个库的结果
部分发表的here~~V 为接受的答案。结果
在这些日子里,我发现,Ubuntu的决定虽然在Windows下它的工作完美,在Linux下移动到LibreOffice的,所以我想我的库LibreOffice的最新的稳定版本结果
我收到此错误:

In the past I wrote a C# library to work with OpenOffice and this worked fine both in Windows than under Ubuntu with Mono.
Part of this library is published here as accepted answer.
In these days I discovered that Ubuntu decided to move to LibreOffice, so I tried my library with LibreOffice latest stable release.
While under Windows it's working perfectly, under Linux I receive this error:

Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.



通常单告诉我们哪些库无法加载,这样我就可以安装正确的程序包,一切都OK ,但在这种情况下,我真的不知道发生了什么不好的。

Usually Mono tells us which library can't load, so I can install correct package and everything is OK, but in this case I really don't know what's going bad.

我用 Ubuntu的hardy中我的库编译框架4.0。结果
在Windows下,我不得不写进去的app.config这样的:<?/ p>

I'm using Ubuntu oneiric and my library is compiled with Framework 4.0.
Under Windows I had to write this into app.config:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
</configuration>

由于LibreOffice的组件使用了框架2.0(我认为)。

because LibreOffice assemblies uses Framework 2.0 (I think).

我如何才能找到这个错误的原因,解决它结果
谢谢

How can I find the reason of this error to solve it?
Thanks

更新:结果
即使有编制框架2.0的问题(如预期)是一样的。结果
题(我认为)是Mono是没有找到 CLI-UNO桥包(可安装在以前的Ubuntu版本和现在被标记为取代),但我不能肯定。

UPDATE:
Even compiling with Framework 2.0 problem (as expected) is the same.
Problem (I think) is that Mono is not finding cli-uno-bridge package (installable on previous Ubuntu releases and now marked as superseded), but I cannot be sure.

更新2:结果
我创建了一个测试控制台应用程序在Windows上引用CLI-UNO的DLL(它们被登记在GAC_32和GAC_MSIL)。

UPDATE 2:
I created a test console application referencing cli-uno dlls on Windows (they are registered in GAC_32 and 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"));
    }
}



库:

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;
            }
        }
    }
}



但我无法看到的启动!结果
。如果我评论用(...)上的应用程序,我看行控制台...所以我认为这是一些错误的DLL。在那里,我又不是能看到的初始化输入的init()消息()。行为是相同的,当未​​安装的LibreOffice并且当它是!!! 在try..catch 块未执行...结果
我开始认为单找不到LibreOffice的CLI库...结果
我用数据库更新然后定位找到他们,但我总是得到一个空的结果;我不明白,在Windows上一切正常......

but I'm not able to see "Starting" !!!
If I comment using(...) on application, I see line on console... so I think it's something wrong in DLL. There I'm not able to see "Entering Init()" message on Init(). Behaviour is the same when LibreOffice is not installed and when it is !!! try..catch block is not executed...
I start to think that mono cannot find LibreOffice CLI libraries...
I used updatedb and then locate to find them, but I always get an empty result; I don't understand, on Windows everything works...

更新3:结果
后汉斯评论,我刚刚打开去除一切,但的init()在我的图书馆,但仍错误。因此,我搬到了动态

UPDATE 3:
After Hans comment, I've just removed everything but Init() in my library but error remained. So I moved to dynamic

//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);
    }
}

和现在的控制台,我能看到

and now in console I'm able to see

启动

未处理的异常:System.IO.FileNotFoundException:未能加载
档或程序集cli_uretypes,版本= 1.0.8.0,文化=中立,
公钥= ce2cb7e279207b9e'或其依赖项之一。

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'cli_uretypes, Version=1.0.8.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e' or one of its dependencies.

这并没有解决我的问题,而且有利于!!结果
的问题是:为什么LibreOffice中的Linux安装(安装包+ SDK)不安装这个库

This doesn't solve my problem, but helps!!
Question is: why LibreOffice's Linux installation (installation package + SDK) does not install this library?

推荐答案

我终于回答我的问题,但我要感谢@Hans帮我找到隐藏的问题。结果
当我写,尝试运行使用LibreOffice的单一个简单的应用程序,我得到这个错误

I finally answer my question, but I want to thank @Hans for helping me in finding hidden problem.
As I wrote, trying to run a simple app with Mono using LibreOffice, I got this error

未处理的异常:System.TypeLoadException:A型负载例外$发生b $ b结果
[错误] FATAL未处理的异常:
System.TypeLoadException:发生A型负载例外

Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.

有没有办法让单告诉我,这是错误,也不是我的应用程序被写任何东西来安慰,所以我可以了解哪些零件/线路引发错误。结果
一在汉斯回答款给我指了路。

There was no way to let Mono tell me which was the error, nor my app was writing anything to console so I could understand which part/line raise the error.
A paragraph in Hans answer showed me the way

在.NET框架有一个真正的刚刚即时编译器。单不,它
有一个AOT(时间提前)编译器。换句话说,它积极
编译装配中的所有代码,而不仅是即将被执行

The .NET framework has a true just-in-time compiler. Mono doesn't, it has an AOT (Ahead Of Time) compiler. In other words, it aggressively compiles all the code in the assembly, not just what is about to be executed.

所以,当我宣布

private XComponentContext context;
private XMultiServiceFactory service;
private XComponentLoader component;
private XComponent doc;



单尝试找到正确的在执行应用程序引用的程序集,而不是当这些线路将被处理!想到这里,我决定在动态移动搜索
所以我删除变量的声明和使用。

Mono tries to find referenced assemblies right when the app is executed, not when those lines are to be processed! Thinking about this, I decided to move on dynamics.
So I removed variables declaration and used:

//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");



再次执行我的应用程序,我能够看到控制台消息我的预期,最后,当行 VAR背景= ... 进行了处理我

未处理的异常:System.IO。 FileNotFoundException异常:无法加载
文件或程序集cli_uretypes,版本= 1.0.8.0,文化=中立,
公钥= ce2cb7e279207b9e或它的一个依赖

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'cli_uretypes, Version=1.0.8.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e' or one of its dependencies.

所以,我终于找到了问题:LibreOffice的在Ubuntu 11.10没有安装 CLI界面包键,这个包已经被剥夺关闭与当前Ubuntu发行。结果
即使我试图手动安装其他老包,甚至把一些rpm包,我是不是能够使用LibreOffice中使用Mono。结果
太糟糕了,因为即使使用以前的OpenOffice分布有 CLI-UNO桥包做这个工作。希望在未来能有更好......结果
我也试图在发布 AskUbuntu ,但没有有用的答案都在这一刻定。

So I finally managed to find the problem: LibreOffice in Ubuntu 11.10 does not install CLI interface package and this package has been stripped off from current Ubuntu distribution.
Even if I tried to manually install other older packages, even converting some rpm package, I was not able to use LibreOffice with Mono.
Too bad, even because with previous distribution using OpenOffice there was cli-uno-bridge package doing this job. Hope better in future...
I also tried to post a question at AskUbuntu, but no useful answer were given at this moment.

这篇关于单LibreOffice的System.TypeLoadException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆