在过去,我编写了一个C#库来与OpenOffice一起工作,这在Windows中比在Mono下使用Ubuntu都好。
该图书馆的部分内容已发布here作为公认的答案。
在这些日子里,我发现Ubuntu决定迁移到LibreOffice,所以我尝试使用LibreOffice最新稳定版本的库。
虽然在Windows下它的正常使用,Linux下我收到此错误:Mono-LibreOffice System.TypeLoadException
Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.
通常单告诉我们哪些库无法加载,这样我就可以安装正确的包装,一切都OK,但在这种情况下,我真的不知道发生了什么坏事。
我使用的是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>
因为LibreOffice的组件使用框架2.0(我认为)。
如何找到此错误的原因来解决它?
由于
UPDATE:
与框架2.0问题即使编译(如预期)是相同的。
问题(我认为)是单声道没有找到cli-uno-bridge
包(可安装在以前的Ubuntu发布,现在标记为取代),但我不能确定。
更新2:
我创建了一个测试控制台应用程序在Windows上引用CLI-UNO的DLL(它们被登记在GAC_32和GAC_MSIL)。
控制台应用程序
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()上的"Entering Init()"
消息。当LibreOffice没有安装,它的行为是一样的!不执行try..catch
块...
我开始认为单找不到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);
}
}
,现在在控制台我能看到
Starting
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)不安装这个库?
刚刚发布自己的答案,如果没有人来了一个更好的。 – 2012-04-16 12:51:11
@HansPassant:你为什么删除你的答案?它帮助了我很多,并有很多良好的知识海事组织... – Marco 2012-04-16 13:09:58
呃,没有人投票它有帮助,你更新了问题,包括答案。我会保存它的另一个问题:) – 2012-04-16 13:23:09