Mono-LibreOffice System.TypeLoadException

前端 未结 3 959
情歌与酒
情歌与酒 2021-01-22 01:44

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

3条回答
  •  渐次进展
    2021-01-22 01:58

    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

    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

    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.

    So when I declare

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

    Executing my app again, I was able to see console messages I expected and finally, when line var context = ... were processed I got

    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.

    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.

提交回复
热议问题