Ask Your Question
0

C# Build remote connection to LibreOffice

asked 2018-09-28 08:48:28 +0200

Kees van Spelde gravatar image

Hi,

I'm trying to write a program that start LibreOffice with a pipe connection and then connects to it. But what ever I try I always end up with the exception Unable to cast transparent proxy to type 'unoidl.com.sun.star.frame.XComponentLoader'.

I'm starting LibreOffice this way:

        var process = new Process
        {
            StartInfo =
            {
                Arguments =
                    $"-invisible -nofirststartwizard -minimized -nologo -nolockcheck -env:UserInstallation=file:///{_userFolder} --accept=pipe,name={_pipeName};urp;StarOffice.ServiceManager",
                FileName = installPath + @"\soffice.exe",
                CreateNoWindow = true
            }
        };

        if (!process.Start())
            throw new InvalidProgramException("Could not start LibreOffice");

        _libreOfficeProcess = process;

And then try to connect to it this way:

            var localContext = Bootstrap.defaultBootstrap_InitialComponentContext();
            var localServiceManager = localContext.getServiceManager();
            var urlResolver = (XUnoUrlResolver) localServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext);
            Thread.Sleep(1000);
            var remoteContext = (XComponentContext) urlResolver.resolve($"uno:pipe,name={_pipeName};urp;StarOffice.ComponentContext");
            var remoteFactory = (XMultiServiceFactory) remoteContext.getServiceManager();
            var componentLoader = (XComponentLoader) remoteFactory.createInstance("com.sun.star.frame.Desktop"); 
            component = InitDocument(componentLoader, ConvertToUrl(inputFile), "_blank");

But the line var componentLoader = (XComponentLoader) remoteFactory.createInstance("com.sun.star.frame.Desktop"); then throws the exception.

What am I doing wrong?

Greetings, Kees van Spelde

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-05-03 23:01:45 +0200

You need to set the URE_BOOTSTRAP environment variable before starting the LibreOffice process:

Environment.SetEnvironmentVariable("URE_BOOTSTRAP", $"vnd.sun.star.pathname:{InstallationPath}/fundamental.ini");
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-09-28 08:48:28 +0200

Seen: 117 times

Last updated: May 03