Mono-LibreOffice System.TypeLoadException

Posted by Marco on Stack Overflow See other posts from Stack Overflow or by Marco
Published on 2012-04-05T13:35:19Z Indexed on 2012/04/16 11:28 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

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.

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.

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>

because LibreOffice assemblies uses Framework 2.0 (I think).

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

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.

UPDATE 2:
I created a test console application referencing cli-uno dlls on Windows (they are registered in GAC_32 and GAC_MSIL).

CONSOLE app

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

LIBRARY:

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

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...

© Stack Overflow or respective owner

Related posts about c#

Related posts about mono