Ask Your Question

C# Build remote connection to LibreOffice

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

Kees van Spelde gravatar image


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

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("", localContext);
            var remoteContext = (XComponentContext) urlResolver.resolve($"uno:pipe,name={_pipeName};urp;StarOffice.ComponentContext");
            var remoteFactory = (XMultiServiceFactory) remoteContext.getServiceManager();
            var componentLoader = (XComponentLoader) remoteFactory.createInstance(""); 
            component = InitDocument(componentLoader, ConvertToUrl(inputFile), "_blank");

But the line var componentLoader = (XComponentLoader) remoteFactory.createInstance(""); 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

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", $"{InstallationPath}/fundamental.ini");
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 117 times

Last updated: May 03