https://bugs.documentfoundation.org/show_bug.cgi?id=64070

Michele Locati <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
                 CC|                            |[email protected]
             Status|RESOLVED                    |REOPENED

--- Comment #6 from Michele Locati <[email protected]> ---
This is still valid as of LibreOffice 7.3.

This exact same code works with .Net Framework 4.8, but not with .Net 6.


static int Main()
{
    string programPath = GetProgramPath();

    System.Environment.SetEnvironmentVariable(
        "UNO_PATH",
        programPath,
        System.EnvironmentVariableTarget.Process
    );
    System.Environment.SetEnvironmentVariable(
        "URE_BOOTSTRAP",
        $"vnd.sun.star.pathname:{System.IO.Path.Combine(programPath,
"fundamental.ini")}",
        System.EnvironmentVariableTarget.Process
    );
    System.Environment.SetEnvironmentVariable(
        "PATH",
       
$"{programPath}{System.IO.Path.PathSeparator}{System.Environment.GetEnvironmentVariable("PATH")}",
        System.EnvironmentVariableTarget.Process
    );
    try
    {
        uno.util.Bootstrap.defaultBootstrap_InitialComponentContext();
        System.Console.Out.WriteLine("OK!");
        return 0;
    }
    catch (System.Exception x)
    {
        System.Console.Error.WriteLine(x.GetType().FullName);
        System.Console.Error.WriteLine(x.Message);
        System.Console.Error.WriteLine(x.StackTrace);
        return 1;
    }
}

private static string GetProgramPath()
{
    var programPath = Microsoft.Win32.Registry.GetValue(
        Microsoft.Win32.Registry.LocalMachine.Name +
@"\SOFTWARE\LibreOffice\UNO\InstallPath",
        "",
        null
    ) as string;
    if (string.IsNullOrEmpty(programPath))
    {
        throw new System.Exception("Failed to detect the program path");
    }
    return programPath;
}



When executed with .Net Framework 4.8 everithing works just fine.

When executed with .Net 6 we have:

System.InvalidOperationException
Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at uno.util.to_cli<class
com::sun::star::uno::XComponentContext>(Reference<com::sun::star::uno::XComponentContext>*
x)
   at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(String
ini_file, IDictionaryEnumerator bootstrap_parameters)
   at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext()
   at ConsoleDotNetFramework.Program.Main() in Program.cs:line 26
```

PS: I published a simple Visual Studio solution to showcase this: see
https://github.com/mlocati/libreoffice-uno-dotnet

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to